Last active
November 10, 2015 07:18
-
-
Save Deepwalker/c3ad8dbe47e4f90fb408 to your computer and use it in GitHub Desktop.
Комментарии относительно вставки скрипта GA для новичков
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(win, docmnt, tagname, ga_link, ga_func_name, a, m) { | |
// записываем на объект window имя нашей ga функции, которая обычно 'ga' | |
win['GoogleAnalyticsObject'] = ga_func_name; | |
// присваиваем window.ga функцию, если она еще не создана | |
win[ga_func_name] = win[ga_func_name] || function() { | |
// инициализируем массив window.queue, если его еще нет | |
// и кладем в него параметры, с которыми вызвали ga(...arguments) | |
(win[ga_func_name].queue = win[ga_func_name].queue || []).push(arguments) | |
}; | |
win[ga_func_name].l = 1 * new Date(); | |
// создаем DOM ноду <script> и грузим в него большой скрипт аналитики | |
a = docmnt.createElement(tagname), | |
m = docmnt.getElementsByTagName(tagname)[0]; | |
a.async = 1; | |
a.src = ga_link; | |
// ну и вставляем ноду в документ | |
m.parentNode.insertBefore(a, m) | |
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); | |
ga('create', 'UA-BLABLABLA', 'auto'); | |
ga(function(tracker) { | |
var clientId = tracker.get('clientId'); // get client id from Google Analytics | |
document.cookie = "_ga_cid=" + clientId + "; path=/"; // save it to cookie _ga_cid | |
document.cookie = "cid=" + clientId + "; path=/"; // save it to cookie cid | |
ga('set', 'dimension1', clientId); //запись clientId для каждого пользователя | |
}); | |
ga('send', 'pageview'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment