jellekralt / Responsive-Tabs

Responsive Tabs is a jQuery plugin that provides responsive tab functionality. The tabs transform to an accordion when it reaches a CSS breakpoint. You can use this plugin as a solution for displaying tabs elegantly on desktop, tablet and mobile.
http://jellekralt.github.io/Responsive-Tabs/
MIT License
531 stars 228 forks source link

Trigger Google Analytics Event #95

Closed Dooza closed 8 years ago

Dooza commented 8 years ago

Hi there, I want to fire off a Google Analytics event when someone clicks a tab. Has anyone done this before? I think I need to use "activate", but not sure how to get the name of the tab. Any ideas?

Cheers,

Dooza

Dooza commented 8 years ago

Figured it out:

activate: function(event, tab) {
ga('send','event','Tab','Clicked',tab.selector);
}

The only issue is that it fires as soon as the page loads as well as when a tab is clicked. I would prefer it to fire on just tab clicks. Any ideas?

Dooza

jellekralt commented 8 years ago

To solve it in a simple way you could do:

$(document).ready(function () {
    var activated = false;

    $('#tab').responsiveTabs({
        activate: function(e, tab) {
            if (activated) {
                // Do your stuff
            }

            activated = true;
        }
    });
});