{"id":33908,"date":"2019-03-02T09:08:58","date_gmt":"2019-03-02T09:08:58","guid":{"rendered":"http:\/\/getshortcodes.com\/?post_type=docs&#038;p=33908"},"modified":"2019-03-25T18:13:35","modified_gmt":"2019-03-25T18:13:35","slug":"tracking-tab-opening-in-google-analytics","status":"publish","type":"docs","link":"https:\/\/getshortcodes.com\/docs\/tracking-tab-opening-in-google-analytics\/","title":{"rendered":"Tracking tab opening in Google Analytics"},"content":{"rendered":"\n<p>This article presents&nbsp;the example&nbsp;of JavaScript-code. The code should be placed in the main file of your&nbsp;current&nbsp;active theme scripts. If you don&#8217;t know where to paste JavaScript-code you can use a special&nbsp;<a href=\"https:\/\/wordpress.org\/plugins\/custom-javascript-editor\/\">plugin<\/a>.<\/p>\n\n\n\n<p>Don&#8217;t forget to connect Google Analytics to your website.<\/p>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><div class=\"su-tabs su-tabs-style-default su-tabs-mobile-stack\" data-active=\"1\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-tabs-nav\"><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">Tab title<\/span><span class=\" my-custom-tab\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">Tab title<\/span><\/div><div class=\"su-tabs-panes\"><div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"Tab title\"> Content <\/div>\n<div class=\"su-tabs-pane su-u-clearfix su-u-trim my-custom-tab\" data-title=\"Tab title\"> Content <\/div><\/div><\/div><\/pre>\n\n\n\n<p>Now you can use the following JavaScript code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">jQuery(document).ready(function($) {<br>  \/\/ Handle tab title click<br>  $('.su-tabs-nav').on('click', '.my-custom-tab', function() {<br>    setTimeout(function() {<br>      \/\/ Track event in GA<br>      ga('send', {<br>        hitType: 'event',<br>        eventCategory: 'Tabs',<br>        eventAction: 'clicked',<br>        eventLabel: 'Shortcodes Ultimate Campaign'<br>      });<br>    }, 100);<br>  });<br>});<\/pre>\n","protected":false},"featured_media":0,"template":"","docs_category":[23],"class_list":["post-33908","docs","type-docs","status-publish","hentry","docs_category-customization"],"_links":{"self":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs\/33908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/types\/docs"}],"wp:attachment":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/media?parent=33908"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs_category?post=33908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}