Search code examples
slidergoogle-tag-managerslick.js

is there away to track slider swiping using GTM?


I am looking for a methodology to track when user swipe the slider to the right or to the left only! not anything else, only swiping.


Solution

  • It's possible with a custom event. This is how to capture the swipe event with the direction. First, push a custom event to the dataLayer when a slider swipe event is triggered:

    <script>
        $('#slider').on('swipe', function (event, slick, direction) {
            dataLayer.push({"event": "sliderSwipe", "swipeDirection": direction});
        });
    </script>
    

    In GTM, create a custom trigger:

    Trigger name: Slider Swipe
    Trigger type: Custom Event
    Event name: sliderSwipe
    Trigger fires on: All custom events
    

    Create a user-defined variable:

    Variable name: Swipe Direction
    Variable type: Data Layer Variable
    Data layer variable name: swipeDirection
    

    Create a new tag:

    Tag type: Google Analytics: Universal Analytics
    Category: Slider
    Action: Swipe
    Label: {{Swipe Direction}}
    Trigger:  Slider Swipe