// GA (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','__gaTracker'); __gaTracker('create', ' ID', { 'storage': 'none', 'clientId': 'Id /' }); // dummy /** * Dummy analytics tracker function. * * @param {...} var_args */ function __gaTracker(var_args) {} // namespace var SiteNamespace = window.SiteNamespace || {}; SiteNamespace._ga_cache = {}; /** * * * @param {Boolean} once - "" * ( ) * @param {String} category - * @param {String} action - * @param {String} [label] - * @param {Number} [value] - */ SiteNamespace.trackGAEvent = function(once, category, action, label, value) { if (typeof __gaTracker === 'undefined') { return; } var cache = SiteNamespace._ga_cache; if (!cache[category]) { cache[category] = {}; } if (!cache[category][action]) { cache[category][action] = {}; } if (cache[category][action][label]) { if (once) { // track only first usage return; } } else { cache[category][action][label] = true; } var opts = { hitType: 'event', eventCategory: category, eventAction: action }; if (typeof label !== 'undefined') { opts['eventLabel'] = label; } if (typeof value !== 'undefined') { opts['eventValue'] = value; } __gaTracker('send', opts); };
Source: https://habr.com/ru/post/193528/
All Articles