Tagged: google tag manager, LayerSlider
-
AuthorPosts
-
May 27, 2022 at 7:43 pm #1353213
I found an older thread on this topic but no clear answer: https://kriesi.at/support/topic/layerslider-click-tracking/
Can you provide any additional guidance on how we can code elements on a slider in layerslider so that Google Tag Manager captures unique clicks?
May 27, 2022 at 9:02 pm #1353225Hey beverlystone,
I believe this thread should help: Add onclick event in button shortcode
The thread refers to a button but the onclick event is added to the link of the button (a) so the same can be applied to any link.Best regards,
MikeMay 28, 2022 at 12:16 am #1353249I’m not sure that thread is helping and I’m concerned about how old it is. I am thinking that the code should resemble something like this:
a href=”https://mywebsite.com/page/” onClick=”_gaq.push([‘_trackEvent’, ‘Banner’, ‘Click’, ‘BSO’,’1′]);” style=”color:#fff;”>Book Now</a
I had to remove the opening and closing tags < > to not have it link.
But the key element – once I customize that code – is that I cannot figure out is where in the layerslider this will go. I have a handful of images I’d like to track.
- This reply was modified 2 years, 7 months ago by beverlystone.
May 28, 2022 at 1:32 pm #1353269Hi,
Thanks for the feedback, the script adds the onclick attribute to the link from the functions.php based on the like custom class.
so if you consider this code:
jQuery('.ga-buy a').attr('onclick', 'ga(\'send\', \'event\', \'Buy Button\', \'Resume\', \'Resume Template Download\')\;');
the link custom class ga-buy is the target, wherever this class is found the attribute onclick is added.
With this method you are not editing the link itself so there is no URL as in your example.Now the question is onClick’,’_gaq.push( correct or is onclick’,’ga( correct?
I don’t use Google Analytics but this document points to gtag now being correct.
If this is correct I would try this script in your functions.php:function add_custom_gtag(){ ?> <script> (function($){ $('.custom-class a').attr('onclick', 'gtag(\'event\', \'Banner\', \'Click\', \'BSO\')\;'); })(jQuery); </script> <?php } add_action('wp_footer', 'add_custom_gtag');
with your link having the custom class: custom-class
I would recommend first setting up a test page with a plain image link and a custom class to test this to see if it is logging in your Google Analytics correctly.Best regards,
MikeMay 28, 2022 at 1:44 pm #1353270Are you saying that this custom CSS is the ticket to tracking clicks from layerslider images? If yes, I do see in the layersider where a custom class can be added to images.
May 28, 2022 at 2:43 pm #1353271Hi,
In the layerslider you would click your image, then attributes, then add the custom class:
But you can also add the onclick attribute directly in the layerslider without using the script or the custom class in the custom attribute field:
onclick
gtag('event', 'Banner', 'Click', 'BSO');
So that would probably be the easiest solution for you
Best regards,
MikeMay 31, 2022 at 2:11 am #1353515Thank you! I’ll give that a go and let you know how I do.
May 31, 2022 at 12:20 pm #1353577June 1, 2022 at 5:38 pm #1353780This worked like a charm! I used this code: gtag(‘event’, ‘homeslider’, { ‘event_category’ : ‘icon’, ‘event_label’ : ‘containers’ });
Last question. Should I short the code I used to follow the same pattern you gave me?
gtag(‘event’, ‘Banner’, ‘Click’, ‘BSO’); would become gtag(‘event’, ‘homeslider’, ‘icon’, ‘containers’);
Will that work as well?
June 1, 2022 at 5:39 pm #1353781BTW, are you able to fix the title of this post? I typed in Layerslides instead of Layerslider.
June 1, 2022 at 5:52 pm #1353782Hi,
Glad to hear this is working for you, you could change the pattern if it suits your needs in Google Analytics, I imagine you will want it descriptive enough that you understand where the click came from.
Unfortunately, I can’t edit the title but the Topic Tags and thread content should be enough that other users will find this helpful, unless there is anything else we can help with on this issue, shall we close this then?Best regards,
MikeJune 1, 2022 at 6:00 pm #1353784Yes. You can close this thread. Thank you again!
June 1, 2022 at 6:31 pm #1353805Hi,
Thanks for letting us know, I’ll close this thread for now then. Please open a new thread if you should have any further questions or problems.
Best regards,
Rikard -
AuthorPosts
- The topic ‘Track clicks in Layerslides’ is closed to new replies.