Google Analytics Event Tracking for Slider Revolution

Track your Slider Revolution clicks with Google Analytics

Table of Content

  • Step 1 : Setup Google Analytics
  • Step 2 : Hyperlink your Slides and/or Layers
  • Step 3 : Add the “ga-button” class to your hyperlinks
  • Step 4 : Add custom JS

Quick Tip

Already have your GA tracking code installed and your slider links setup?

Step 1

Setup your Google Analytics account for your site

If you’re reading this article, chances are you already have Google Analytics (GA) setup for your site.  But if not, here are a few good places to start for setting up GA for your WordPress site:

Getting Started with Google Analytics:
https://support.google.com/analytics/answer/1008015?hl=en

Where to find your Tracking Code:
https://support.google.com/analytics/answer/1032385?hl=en

Setting up your Tracking Code:
https://support.google.com/analytics/answer/1008080?hl=en

WordPress Plugin to connect your GA Account to your site:
https://wordpress.org/plugins/google-analytics-for-wordpress/

Step 2

Hyperlink your Slides and/or Layers

Hyperlink an entire slide:
/documentation/tags-link/#link-to-webpage

Hyperlink a Layer:
/documentation/simple-link/#simple-link

Step 3

Add the “ga-button” class to your hyperlinks.

If hyperlinking an entire Slide:

If hyperlinking a single content Layer:

Step 4

Add the following script to your slider’s Custom JavaScript section.

This code does not need to be modified (straight copy and paste)

Track Outbound Links:

jQuery('body').on('click', '.ga-button', function() {
 
    var $this = jQuery(this),
        data  = $this.attr('data-link') || $this.attr('href');
 
    if(!data) {
 
        data = $this.attr('data-actions');
        if(data) data = data[0].url;
        if(!data) data = $this.attr('id');
 
    }
 
    gtag('event', 'click', { event_category: 'outbound', event_action: 'click', event_label: data});
 
}); 

Track All Slide Changes:

jQuery(window).on('load', function() {
 
    jQuery('.rev_slider').each(function() {
 
        var ids = jQuery(this).attr('id').split('rev_slider_')[1].split('_')[0],
            api  = eval('revapi' + ids);
 
        api.on('revolution.slide.onchange', function(e, data) {
 
            var data = 'Slider ' + ids + ' changed to slide #' + data.slideIndex;
            gtag('event', 'click', { event_category: 'outbound', event_action: 'click', event_label: data});
 
        });
 
    });
 
}); 
Google Analytics Event Tracking for Slider Revolution

The Author

KC

Strength does not come from winning. Your struggles develop your strengths. When you go through hardships and decide not to surrender, that is strength.

Liked this Post?
Please Share it!