Skip to content
This repository
Browse code

Fixed analytics in extension...finally

  • Loading branch information...
commit 6688411cbaa3dc0ac3079a996bbe22bff35a077d 1 parent 4b8df46
David Shorthouse dshorthouse authored
1  app/namespotter/src/background.html
@@ -2,7 +2,6 @@
2 2 <head>
3 3 <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
4 4 <script type="text/javascript" src="js/background.js"></script>
5   -<script type="text/javascript" src="js/ga.js"></script>
6 5 </head>
7 6 <body>
8 7 <form>
23 app/namespotter/src/js/background.js
... ... @@ -1,6 +1,7 @@
1 1 /*global $, jQuery, window, document, escape, alert, delete, self, chrome, localStorage */
2 2
3   -var nsbg = nsbg || {};
  3 +var nsbg = nsbg || {},
  4 + _gaq = _gaq || [];
4 5
5 6 (function() {
6 7
@@ -28,6 +29,19 @@ var nsbg = nsbg || {};
28 29 });
29 30 };
30 31
  32 + nsbg.loadAnalytics = function() {
  33 + _gaq.push(['_setAccount', this.manifest.namespotter.ga]);
  34 + _gaq.push(['_trackPageview']);
  35 +
  36 + var ga = document.createElement('script'),
  37 + s = document.getElementsByTagName('script')[0];
  38 +
  39 + ga.type = 'text/javascript';
  40 + ga.async = true;
  41 + ga.src = 'https://ssl.google-analytics.com/ga.js';
  42 + s.parentNode.insertBefore(ga, s);
  43 + };
  44 +
31 45 nsbg.analytics = function(category, action, label) {
32 46 _gaq.push(['_trackPageview'], category, action, label);
33 47 };
@@ -127,8 +141,7 @@ var nsbg = nsbg || {};
127 141 break;
128 142
129 143 case 'ns_analytics':
130   - var _gaq = _gaq || [],
131   - category = request.params.category || "",
  144 + var category = request.params.category || "",
132 145 action = request.params.action || "",
133 146 label = request.params.label || "";
134 147
@@ -173,10 +186,10 @@ var nsbg = nsbg || {};
173 186 nsbg.init = function() {
174 187 var self = this;
175 188
176   - self.loadManifest();
177   -
178 189 chrome.browserAction.onClicked.addListener(function() {
179 190 self.cleanup();
  191 + self.loadManifest();
  192 + self.loadAnalytics();
180 193 self.loadSettings();
181 194 self.sendRequest();
182 195 });
8 app/namespotter/src/js/ga.js
... ... @@ -1,8 +0,0 @@
1   -var _gaq = _gaq || [];
2   -_gaq.push(['_setAccount', nsbg.manifest.namespotter.ga]);
3   -_gaq.push(['_trackPageview']);
4   -(function() {
5   - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
6   - ga.src = 'https://ssl.google-analytics.com/ga.js';
7   - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
8   -})();
2  app/namespotter/src/manifest.json
... ... @@ -1,6 +1,6 @@
1 1 {
2 2 "name" : "Global Names NameSpotter",
3   - "version" : "0.3.0",
  3 + "version" : "0.3.1",
4 4 "description" : "__MSG_manifest_description__",
5 5 "background_page" : "background.html",
6 6 "icons" : {

0 comments on commit 6688411

Please sign in to comment.
Something went wrong with that request. Please try again.