Answer the question
In order to leave comments, you need to log in
How to collect ga statistics in an extension?
The bottom line is that there are extensions, I created a code for it in ga, I put it in popup.js, everything works fine (when you click on the extension, it will work and send the stat to ga)
In parallel, my extension has a content script for one site, so I want to collect the stat when the user comes to the site and the script started up
. If you put the code in content_script.js
, then the goal does not work, if you put the code at the beginning, then the whole script goes to
content_script.js code
$( document ).ready(function() {
/*
Много всякого кода
что то делаю на странице
радактирую DOM
прочая лабуда
*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-ТУТКОД-СТОИТ']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question