我写了一个chrome扩展程序,当单击扩展程序图标时,它会在新标签上打开一个网址。我想知道单击图标时如何跟踪新打开页面的网址。目前,谷歌分析似乎并未注册我的活动。 这是我的一些代码。
mainfest.json:
{
"name": "Extension name",
"description": "Description",
"version": "1.0.1"
"background":
{
"scripts": ["js/background.js", "js/eventPage.js", "js/ga.js", "js/jquery-3.2.1.min.js"],
"persistent":false
},
"page_action": {
"default_icon":"Logo.png"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*",
"activeTab"
],
"content_security_policy": "script-src 'self' https://www.google-analytics.com/analytics.js; object-src 'self'"
}
ga.js:
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-XX', 'auto');
ga('set', 'checkProtocolTask', function(){});
ga('require', 'displayfeatures');
ga('send', 'pageview', '/mypage.html');
chrome.pageAction.onClicked.addListener(function(tab) {
ga('send', {
hitType: 'event',
eventCategory: 'PageUrl',
eventAction: 'click',
eventLabel: 'Display new page url'
});
});