Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #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?

    #1353225

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

    #1353249

    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=”https://mywebsite.com/page/&#8221; 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.
    #1353269

    Hi,
    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,
    Mike

    #1353270

    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.

    #1353271

    Hi,
    In the layerslider you would click your image, then attributes, then add the custom class:
    2022-05-28_001.jpg
    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:
    2022-05-28_002.jpg
    onclick gtag('event', 'Banner', 'Click', 'BSO');
    So that would probably be the easiest solution for you
    2022-05-28_003.jpg

    Best regards,
    Mike

    #1353515

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

    #1353577

    Hi,
    Very Good

    Best regards,
    Mike

    #1353780

    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?

    #1353781

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

    #1353782

    Hi,
    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,
    Mike

    #1353784

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

    #1353805

    Hi,

    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

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