Home › Forums › Theme Support › Cassiopeia › Google Analytics on the read more button
- This topic has 16 replies, 2 voices, and was last updated 10 years, 6 months ago by generation10.
-
AuthorPosts
-
May 12, 2014 at 1:36 pm #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
May 12, 2014 at 8:13 pm #3045Hi 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!
ChrisMay 13, 2014 at 7:46 am #3050The 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
May 13, 2014 at 5:15 pm #3056Hi,
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!
May 14, 2014 at 7:40 am #3060Yes, 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 🙂
May 15, 2014 at 4:02 pm #3068Hey,
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!
ChrisJune 2, 2014 at 1:19 pm #3215This reply has been marked as private.June 3, 2014 at 10:15 am #3217This reply has been marked as private.June 3, 2014 at 11:13 am #3218I 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
June 3, 2014 at 7:06 pm #3238Hi 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!
June 4, 2014 at 8:29 am #3246It is not echoing the onclick variable on the button link :/
Thanks
🙂
June 11, 2014 at 12:55 pm #3313How did you insert the shortcode into the page? Can you post an example?
Cheers!
June 16, 2014 at 2:12 pm #3375This reply has been marked as private.June 17, 2014 at 12:41 pm #3382This reply has been marked as private.June 17, 2014 at 2:49 pm #3391Hmm, 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!
-
AuthorPosts
You must be logged in to reply to this topic.