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?
ThanksMay 12, 2014 at 8:13 pm #3045
Do you get any errors? There shouldn’t be a problem adding your code in the “Tracking Code” box in the theme options page.
ChrisMay 13, 2014 at 7:46 am #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 🙂
BernardoMay 13, 2014 at 5:15 pm #3056
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 #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 🙂May 15, 2014 at 4:02 pm #3068
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' => '#',
'id' => '',
Now, just before line 325, this:
$variation = ($style) ? ' '.$style. '_gradient' : '';
$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>';
$out = '<a '. $button_id .' ' .$button_target. ' class="button_link' .$variation.$size.$align. '" href="' .$link. '" '.$nofollow.'><span>' .do_shortcode($content). '</span></a>';
Now, when you insert the shortcode, simply add the id attribute.
Let me know how’s going.
ChrisJune 2, 2014 at 1:19 pm #3215June 3, 2014 at 10:15 am #3217June 3, 2014 at 11:13 am #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>';
ThanksJune 3, 2014 at 7:06 pm #3238
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 #3246
It is not echoing the onclick variable on the button link :/
🙂June 11, 2014 at 12:55 pm #3313
How did you insert the shortcode into the page? Can you post an example?
Cheers!June 16, 2014 at 2:12 pm #3375June 17, 2014 at 12:41 pm #3382June 17, 2014 at 2:49 pm #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?
You must be logged in to reply to this topic.