javascript - Can I add Google Analytics to a Chrome extension which doesn't have a popup.html? -
my chrome extension recognising specific tab's url, , then, on icon click, modifies active tab's content. gauge usage of it, in way. extension's logic:
- manifest.json [injecting jquery & jquery plugin] - background.js [ on extension's icon click, executes content_script.js , tracking.js] - icon - content_script.js [ modifies page content ] - tracking.js (ga code, provided google analytics modified according https://davidsimpson.me/2014/05/27/add-googles-universal-analytics-tracking-chrome-extension/ );
i see how many times extension's button clicked. tried adding appropriate permissions manifest.json:
"content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'"
and adding analytics code separate .js file (tracking.js), , executing when extension's icon clicked, specified in background.js below:
chrome.browseraction.onclicked.addlistener( function(tab) { chrome.tabs.executescript(null, {file: "content_script.js"}); chrome.tabs.executescript(null, {file: "tracking.js"}); });
.. doesn't work, in sense google analytics telling me 'tracking not installed', , cannot think of way of adding it.
how can see extension's usage?
what trying inject tracking tab content script.
tracking works adding <script>
tag page, kicks out of content script's isolated context , page's context. that's why script can't see tracking enabled (and possibly broke page's own tracking too).
you need install tracking code in background page , send events there. so, include tracking.js
list of background scripts; after that, send events in usual ga way.
Comments
Post a Comment