1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to add Google events tracking code to CTA button on popup?

Discussion in 'Google Analytics' started by runningfree73, Nov 7, 2015.

  1. #1
    I have installed a pop-up plugin on my Wordpress site. The pop-up has a CTA button that links to an inner page and I would like to track clicks on the button using Google events tracking.
    SEMrush
    This is the Google analytics code I'm using:
    onClick="ga('send', 'event', { eventCategory: 'popup', eventAction: 'click'});"
    Code (markup):
    ...and the following code is from the plugin which outputs the CTA button link:
    if ( $has_cta ) {
            $cta_button_tag = sprintf(
                '<a href="%1$s" class="wdpu-cta" target="%2$s">%3$s</a>',
                esc_url( $this->cta_link ),
                esc_attr( $cta_target ),
                esc_html( $this->cta_label )
            );
    Code (markup):
    I already tried adding the code directly to the anchor tag but am getting an error when loading the site admin page:
    Parse error: syntax error, unexpected T_STRING in...
    Code (markup):
    Also I was wondering do I need to add anything to the Google analytics code in my site's header file to get the tracking code to work?
     
    runningfree73, Nov 7, 2015 IP
    SEMrush