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

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #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?

    Thanks

    #3045

    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.

    Cheers!
    Chris

    #3050

    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 πŸ™‚

    Cheers,

    Bernardo

    #3056

    Hi,

    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.

    Cheers!

    #3060

    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 πŸ™‚

    #3068

    Hey,

    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.

    Example:

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

    Let me know how’s going.

    Cheers!
    Chris

    #3215
    This reply has been marked as private.
    #3217
    This reply has been marked as private.
    #3218

    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' : '';
    
    	if(empty($rel))
    	$nofollow = '';
    	else
    	$nofollow = 'rel="'.$rel.'"';
    
    	if(empty($target))
    	$button_target = '';
    	else
    	$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?

    Thanks

    #3238

    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?

    Cheers!

    #3246

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

    Thanks

    πŸ™‚

    #3313

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

    Cheers!

    #3375
    This reply has been marked as private.
    #3382
    This reply has been marked as private.
    #3391

    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?

    Cheers!

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

You must be logged in to reply to this topic.