Home Forums Theme Support Cassiopeia Google Analytics on the read more button

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
  • #3038

    Hello everyone 🙂

    I’m trying to add the Google Analytics event tracking code on the read more button but it doesn’t allow me to add the required jQuery.

    Should I add it on the shortcode.php?



    Hi there,

    Do you get any errors? There shouldn’t be a problem adding your code in the “Tracking Code” box in the theme options page.



    The thing is, I want to add it to one specific button and they don’t have IDs so that I can’t specifically target it.
    That is why I wanted to place the code on the button.
    By doing it the way you suggest, I’ll have to create a filter on my GA to get the button from a particular page.

    I don’t know if I was clear enough.

    But thanks for your time 🙂





    Sorry I read the first question wrong. I thought you were trying to insert some normal tracking code (site wide).

    Unfortunately I don’t know how GA events work because I never worked with it. Does it handle the buttons via ids and classes?

    If so I can guide you on how to change the button shortcode code a little bit in order to give each button an unique class or id.



    Yes, it does track events like button clicks via classes or ids. Preferable through ids though.

    If you can give me a hand on that it will be awesome.

    Thanks 🙂



    Here’s what you need to do:

    Go to the theme’s options page > admin and edit the file named “shortcodes.php”.

    Just before line 315, this:

    'link' => '#',

    add this:

    'id' => '',

    Now, just before line 325, this:

    $variation = ($style) ? ' '.$style. '_gradient' : '';

    add this:

    $button_id = ( !empty($id) ) ? 'id="'.$id.'"' : '';

    On line 340 replace this:

    $out = '<a ' .$button_target. ' class="button_link' .$variation.$size.$align. '" href="' .$link. '" '.$nofollow.'><span>' .do_shortcode($content). '</span></a>';

    with this:

    $out = '<a '. $button_id .' ' .$button_target. ' class="button_link' .$variation.$size.$align. '" href="' .$link. '" '.$nofollow.'><span>' .do_shortcode($content). '</span></a>';

    Save. Done.

    Now, when you insert the shortcode, simply add the id attribute.


    [button id=”#your-unique-id-here”]

    Let me know how’s going.


    This reply has been marked as private.
    This reply has been marked as private.

    I realised my mistake.

    I was trying to use the new analytics code on the old tracker 🙁

    Now I need to place a onClick event on the button. I tried the following but it is not working.

       'id' => '' , 
        'onClick' =>'',
        'link'	=> '#',
        'target'	=> '',
        'style'	=> '',
        'size'	=> '',
        'align'	=> '',
        'rel'	=> ''
        ), $atts));
      $button_id = ( !empty($id) ) ? 'id="'.$id.'"' : ''; 
      $button_onClick = (!empty($onClick))?'onClick="'.$onClick.'"' : ''; 
      $variation = ($style) ? ' '.$style. '_gradient' : '';
      $align = ($align) ? ' align'.$align : '';
      $size = ($size == 'large') ? ' large_button' : '';
    	$nofollow = '';
    	$nofollow = 'rel="'.$rel.'"';
    	$button_target = '';
    	$button_target = 'target="'.$target.'"';
    	$out = '<a '. $button_id .' '. $button_onClick .'  ' .$button_target. ' class="button_link' .$variation.$size.$align. '" href="' .$link. '" '.$nofollow.'><span>' .do_shortcode($content). '</span></a>';

    Any tips?



    Hi there,

    The code looks ok at first sight. Is it not echoing the onclick variable on the button link? Or is it echoing it but it just doesn’t work?



    It is not echoing the onclick variable on the button link :/




    How did you insert the shortcode into the page? Can you post an example?


    This reply has been marked as private.
    This reply has been marked as private.

    Hmm, I’m not sure what the problem may be 🙂 It’s weird.

    Can you try not to use capital letters in the shortcode attributes?


Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.