How to track opening of a tab in Google Analytics

This article presents the example of JavaScript-code. The code should be placed in the main file of your current active theme scripts. If you don't know where to paste JavaScript-code you can use a special plugin.

Don't forget to connect Google Analytics to your website.

It is recommended to add unique CSS-class to the shortcode you are going to track. You can make it, for example, in the following way:

	[su_tab] Content [/su_tab]
	[su_tab class="my-custom-tab"] Content [/su_tab]

Now you can use the following JavaScript code:

jQuery(document).ready(function($) {
  // Handle tab title click
  $('.su-tabs-nav').on('click', '.my-custom-tab', function() {
    setTimeout(function() {
      // Track event in GA
      ga('send', {
        hitType: 'event',
        eventCategory: 'Tabs',
        eventAction: 'clicked',
        eventLabel: 'Shortcodes Ultimate Campaign'
    }, 100);