diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 7c959709..343e0c6b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -7,6 +7,10 @@ "message": "Add Style", "description": "Title of the page for adding styles" }, + "analyticsEnabled": { + "message": "Send anonymous data to Stylish developers for determining user counts", + "description": "Label for the enable analytics setting" + }, "appliesAdd": { "message": "Add", "description": "Label for the button to add an 'applies' entry" diff --git a/analytics.js b/analytics.js index b30f6115..f1b05512 100644 --- a/analytics.js +++ b/analytics.js @@ -2,8 +2,27 @@ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-8246384-4']); _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); -})(); +function isAnalyticsEnabled() { + try { + return chrome.extension.getBackgroundPage().prefs.get("analyticsEnabled"); + } catch (ex) { + console.log(ex); + return true; + } +} + +// Prefs seems not available immediately +setTimeout(function() { + if (isAnalyticsEnabled()) { + (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); + })(); + setInterval(function() { + if (isAnalyticsEnabled()) { + _gaq.push(['_trackPageview']); + } + }, 1000 * 60 * 60 * 24); + } +}, 1000); diff --git a/manage.html b/manage.html index 8cfadee9..d10ee2ad 100644 --- a/manage.html +++ b/manage.html @@ -183,8 +183,9 @@

- +
+

diff --git a/manage.js b/manage.js index 884a9b95..0f705a95 100644 --- a/manage.js +++ b/manage.js @@ -477,7 +477,8 @@ document.addEventListener("DOMContentLoaded", function() { "manage.onlyEnabled", "manage.onlyEdited", "show-badge", - "popup.stylesFirst" + "popup.stylesFirst", + "analyticsEnabled" ]); initFilter("enabled-only", document.getElementById("manage.onlyEnabled")); initFilter("edited-only", document.getElementById("manage.onlyEdited")); diff --git a/storage.js b/storage.js index 93b0c7a6..d10fe299 100644 --- a/storage.js +++ b/storage.js @@ -317,6 +317,7 @@ var prefs = chrome.extension.getBackgroundPage().prefs || new function Prefs() { "windowPosition": {}, // detached window position "show-badge": true, // display text on popup menu icon "disableAll": false, // boss key + "analyticsEnabled": true, // hit up GA on startup "popup.breadcrumbs": true, // display "New style" links as URL breadcrumbs "popup.breadcrumbs.usePath": false, // use URL path for "this URL"