Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Analytics tracking in Chrome Extension's background.html
    primarykey
    data
    text
    <p>When I realized that I cannot track directly in content script. I start to work with background HTML tracking my data. via <a href="https://stackoverflow.com/questions/11372107/content-script-tracking-with-google-analytics/12985606#12985606">Content Script tracking with Google Analytics</a></p> <p>When I set up my background script, I figured out that it doesn't support inline script. So I put the code in a js file and use "src=filename.js" to include that. via <a href="https://stackoverflow.com/questions/11545743/chrome-extension-insert-content-script-on-browser-action">chrome extension insert content script on browser action</a></p> <p>But finally there is a trouble: I cannot load ga.js at all because it still violates the rule. Here is what I got:</p> <blockquote> <p>Refused to load the script '<a href="https://ssl.google-analytics.com/ga.js" rel="nofollow noreferrer">https://ssl.google-analytics.com/ga.js</a>' because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".</p> </blockquote> <p>My extension structure:</p> <ol> <li>background.html</li> <li>script.js</li> <li>tracker.js</li> </ol> <hr> <p>More information about this issue:</p> <p><strong>background.html:</strong></p> <pre><code>&lt;html&gt; &lt;script src="tracker.js"&gt;&lt;/script&gt; &lt;body&gt;&lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>tracker.js:</strong> <em>(I hide my ID)</em></p> <pre><code>var _gaq = _gaq || []; _gaq.push(['_setAccount', _gaID]); _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); })(); </code></pre> <p>Thanks for any kind of help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload