Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
  • #1353213

    I found an older thread on this topic but no clear answer:

    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?


    Hey 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,


    I’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=”; 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 1 year, 12 months ago by beverlystone.

    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(){
    	$('.custom-class a').attr('onclick', 'gtag(\'event\', \'Banner\', \'Click\', \'BSO\')\;');
    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,


    Are 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.


    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,


    Thank you! I’ll give that a go and let you know how I do.


    Very Good

    Best regards,


    This 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?


    BTW, are you able to fix the title of this post? I typed in Layerslides instead of Layerslider.


    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,


    Yes. You can close this thread. Thank you again!



    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,

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Track clicks in Layerslides’ is closed to new replies.