Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Dante › Trouble adding event tracking to shortcode buttons
New Landing › How can we help? › Themeforest Theme Support › Dante › Trouble adding event tracking to shortcode buttons
- This topic has 9 replies, 5 voices, and was last updated 10 years by Rui Guerreiro – SUPPORT.
-
Posted in: Dante
-
August 13, 2014 at 3:30 pm #100757
Hi!
I’m trying to add GA event tracking to my buttons – when I do, I get a mess of code instead of the button text.
I’m about 99% sure my GA is still the old asynch and not the newer universal code because I use Yoast GA and the plugin doesn’t support the universal code yet.
So, how would you recommend I add event tracking to my buttons?
Thanks!
August 13, 2014 at 3:58 pm #100768Hi
Please follow this thread: http://support.swiftideas.net/forums/topic/event-tracking-on-buttons
They managed to do it I think
– Kyle
August 13, 2014 at 5:01 pm #100813Hi Kyle,
I actually went through this thread before reaching out.
She is using the new GA Universal Analytics format:
ga(‘send’, ‘event’, ‘categorie’, ‘actie’, ‘label’);”
I need to know the implementation for this type:
onClick="_gaq.push(['_trackEvent', 'category, action, opt_label, opt_value, opt_noninteraction)']);
August 13, 2014 at 10:51 pm #100869I will forward this to Mohammad, he will be best helping you with this
– Kyle
August 14, 2014 at 3:07 am #100899Hi,
Please add a extraclass to that link and use this code at Admin -> Theme Options -> Custom JS -:<script> jQuery(document).ready(function($){ $("a.eventTrack").click(function(e){ //e.preventDefault(); _gaq.push(['_trackEvent', 'category, action, opt_label, opt_value, opt_noninteraction)']); }); }); </script>
Thanks 🙂
With Best Regards
MohammadAugust 14, 2014 at 2:21 pm #101138Hi Mohammad.
1) What do I name the extra class? Here is what the button code looks like currently:
[sf_button colour="green" type="sf-icon-reveal" size="large" link="/learn-more" target="_blank" icon="fa-thumbs-o-up" dropshadow="yes" extraclass=""]Tell me more[/sf_button]
2) Using your solution above, does that mean I will need to create a new class for every button I want to track? I ask this because ‘category, action, opt_label, opt_value, opt_noninteraction‘ are fields with variables dependent on where the button is and how the user interacts with the button. This way I can see more granularly my data in google analytics.
August 17, 2014 at 4:58 pm #101717Hi,
1- The class name is eventTrack so final code will be:-
[sf_button colour="green" type="sf-icon-reveal" size="large" link="/learn-more" target="_blank" icon="fa-thumbs-o-up" dropshadow="yes" extraclass="eventTrack"]Tell me more[/sf_button]
2- You dont need to create new class to every button.
Thanks 🙂
With Best Regards
MohammadAugust 17, 2014 at 9:06 pm #1017311) The extra class is the last field in the shortcode:
[sf_button colour="green" type="sf-icon-reveal" size="large" link="/learn-more" target="_blank" icon="fa-thumbs-o-up" dropshadow="yes" extraclass="eventTrack"]Tell me more[/sf_button]
2) I’d recommend creating a class for each type, that way you can add the class for each type of tracking.
– Ed
August 18, 2014 at 2:52 pm #102056Hi Ed, Mohammad:
So, if I want unique event tracking for every button I should create unique JS codes?
Example:
Button on careers pageJS:
<script> jQuery(document).ready(function($){ $("a.eventTrackcareera").click(function(e){ //e.preventDefault(); _gaq.push(['_trackEvent', 'button, apply, senioraccountexecutive']); }); }); </script>
Button Code
[sf_button colour="green" type="sf-icon-reveal" size="large" link="/learn-more" target="_blank" icon="fa-thumbs-o-up" dropshadow="yes" extraclass="eventTrackcareera"]Apply[/sf_button]
Then, if for another job position i’d have to create a new iteration of JS code like the following:
<script> jQuery(document).ready(function($){ $("a.eventTrackcareerb").click(function(e){ //e.preventDefault(); _gaq.push(['_trackEvent', 'button, apply, semmanager']); }); }); </script>
With the associated class code:
Button Code
[sf_button colour="green" type="sf-icon-reveal" size="large" link="/learn-more" target="_blank" icon="fa-thumbs-o-up" dropshadow="yes" extraclass="eventTrackcareerb"]Apply[/sf_button]
<br>
Is this the correct implementation?August 20, 2014 at 9:47 am #102551Hi,
Yes is the correct implementation.
In this case the js will be something like the code bellow(add it to the theme custom js option):jQuery(document).ready(function($){ $("a.eventTrackcareera").click(function(e){ //e.preventDefault(); _gaq.push(['_trackEvent', 'button, apply, senioraccountexecutive']); }); $("a.eventTrackcareerb").click(function(e){ //e.preventDefault(); _gaq.push(['_trackEvent', 'button, apply, semmanager']); }); });
-Rui
-
Posted in: Dante
You must be logged in and have valid license to reply to this topic.