AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Friday 4 March 2016

How to add google analytics code in chrome extension?

In this article I will discuss How to add google analytics code in google chrome extension? Google analytic is use to check your site analytic & performance.

Step 1: Add following code in manifest.json file.

 some other code.......
 "content_security_policy": "script-src 'self'; object-src 'self'"

Step 2: Create new javascript file "analytics.js" and write below code

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'your-analytics-is', 'auto'); // Write your analytics id here
  ga('set', 'checkProtocolTask', function(){}); 
  ga('require', 'displayfeatures');
  ga('send', 'pageview', '/CO-Extension.html');

Step 3: Call that file in extension HTML file.
?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" lang="en" xml:lang="en">
    .......some other scripts
    <script type="text/javascript" src="js/analytics.js"></script>   


Post a Comment

  • Popular Posts
  • Comments