Add opt-out for analytics and make it ping once per day

This commit is contained in:
Jason 2016-03-23 21:38:15 -05:00
parent 4c80d9255f
commit 5fb21f2816
5 changed files with 33 additions and 7 deletions

View File

@ -7,6 +7,10 @@
"message": "Add Style", "message": "Add Style",
"description": "Title of the page for adding styles" "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": { "appliesAdd": {
"message": "Add", "message": "Add",
"description": "Label for the button to add an 'applies' entry" "description": "Label for the button to add an 'applies' entry"

View File

@ -2,8 +2,27 @@ var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8246384-4']); _gaq.push(['_setAccount', 'UA-8246384-4']);
_gaq.push(['_trackPageview']); _gaq.push(['_trackPageview']);
(function() { 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; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js'; ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})(); })();
setInterval(function() {
if (isAnalyticsEnabled()) {
_gaq.push(['_trackPageview']);
}
}, 1000 * 60 * 60 * 24);
}
}, 1000);

View File

@ -183,8 +183,9 @@
<p><a href="edit.html"><button id="add-style-label" i18n-text="addStyleLabel"></button></a></p> <p><a href="edit.html"><button id="add-style-label" i18n-text="addStyleLabel"></button></a></p>
<div id="options"> <div id="options">
<h2 id="options-heading" i18n-text="optionsHeading"></h2> <h2 id="options-heading" i18n-text="optionsHeading"></h2>
<input id="show-badge" type="checkbox"><label id="show-badge-label" for="show-badge" i18n-text="prefShowBadge"></label> <div><input id="show-badge" type="checkbox"><label id="show-badge-label" for="show-badge" i18n-text="prefShowBadge"></label></div>
<div><input id="popup.stylesFirst" type="checkbox"><label id="stylesFirst-label" for="popup.stylesFirst" i18n-text="popupStylesFirst"></label></div> <div><input id="popup.stylesFirst" type="checkbox"><label id="stylesFirst-label" for="popup.stylesFirst" i18n-text="popupStylesFirst"></label></div>
<div><input id="analyticsEnabled" type="checkbox"><label id="analyticsEnabled-label" for="analyticsEnabled" i18n-text="analyticsEnabled"></label></div>
</div> </div>
<p id="manage-text" i18n-html="manageText"></p> <p id="manage-text" i18n-html="manageText"></p>
</div> </div>

View File

@ -477,7 +477,8 @@ document.addEventListener("DOMContentLoaded", function() {
"manage.onlyEnabled", "manage.onlyEnabled",
"manage.onlyEdited", "manage.onlyEdited",
"show-badge", "show-badge",
"popup.stylesFirst" "popup.stylesFirst",
"analyticsEnabled"
]); ]);
initFilter("enabled-only", document.getElementById("manage.onlyEnabled")); initFilter("enabled-only", document.getElementById("manage.onlyEnabled"));
initFilter("edited-only", document.getElementById("manage.onlyEdited")); initFilter("edited-only", document.getElementById("manage.onlyEdited"));

View File

@ -317,6 +317,7 @@ var prefs = chrome.extension.getBackgroundPage().prefs || new function Prefs() {
"windowPosition": {}, // detached window position "windowPosition": {}, // detached window position
"show-badge": true, // display text on popup menu icon "show-badge": true, // display text on popup menu icon
"disableAll": false, // boss key "disableAll": false, // boss key
"analyticsEnabled": true, // hit up GA on startup
"popup.breadcrumbs": true, // display "New style" links as URL breadcrumbs "popup.breadcrumbs": true, // display "New style" links as URL breadcrumbs
"popup.breadcrumbs.usePath": false, // use URL path for "this URL" "popup.breadcrumbs.usePath": false, // use URL path for "this URL"