Remove all analytics and user tracking

This commit is contained in:
Jeremy Dormitzer 2018-02-06 13:30:46 -05:00
parent d14a873582
commit 5995d45b5b
No known key found for this signature in database
GPG Key ID: 04F17C0F5A32C320
6 changed files with 16 additions and 133 deletions

View File

@ -2,8 +2,14 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [1.1.0]
### Fixed
- Pointed the Firefox Add-On Store link in the readme to the right URL
- Pointed the Firefox Add-On Store link in the readme to the right URL.
- Fixed project.clj so that the extension can be compiled with no additional profiles enabled>
### Removed
- Removed all analytics and usage tracking.
## [1.0.1]
### Added
@ -17,6 +23,7 @@ All notable changes to this project will be documented in this file. This change
- Functionality to fetch and display Hacker News comments for the current URL.
- Analytics through [Amplitude](https://amplitude.com).
[Unreleased]:https://github.com/jdormit/looped-in/compare/v1.0.1...HEAD
[1.0.0]: https://github.com/jdormit/looped-in/compare/9bf8d142c6a49b743da4b97574dfed0797dd5b2f...v1.0.0
[Unreleased]:https://github.com/jdormit/looped-in/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/jdormit/looped-in/compare/v1.0.1...v1.0.0
[1.0.1]: https://github.com/jdormit/looped-in/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/jdormit/looped-in/compare/9bf8d142c6a49b743da4b97574dfed0797dd5b2f...v1.0.0

View File

@ -21,30 +21,6 @@ This will output the generated JavaScript to `ext/js/generated`.
To load the extension locally in your browser, see [instructions for Firefox](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox) or [instructions for Chrome](https://developer.chrome.com/extensions/getstarted#unpacked).
## Analytics
Looped In uses [Amplitude](https://amplitude.com) to track user actions such as clicking on a story or viewing replies to a comment. This data is useful for improving the program. However, some users find this tracking invasive, so Looped In respects the browser's [Do Not Track](https://www.w3.org/2011/tracking-protection/drafts/tracking-dnt.html) setting. If DNT is enabled, no analytics data is collected. To enable DNT, see [instructions for Firefox](https://support.mozilla.org/en-US/kb/how-do-i-turn-do-not-track-feature?redirectlocale=en-US&redirectslug=how-do-i-stop-websites-tracking-me) and [instructions for Chrome](https://support.google.com/chrome/answer/2790761).
If you are running the extension locally, you will either need to get an Amplitude API key or disable the analytics. The easiest way to disable the analytics is to edit the `src/looped_in/analytics.cljs` file. Delete the bodies of the `init-amplitude` and `log-event` functions. It should look something like this:
```clojure
(defn init-amplitude [] ())
(defn log-event [] ())
```
If you want to keep the analytics, you'll need an Amplitude API key. [Sign up for Amplitude](https://amplitude.com/signup?ref=nav) and follow the getting started guide to create a new project. Once you have the API key, create the file `profiles.clj` at the project root with the following content:
```clojure
{:provided [:cljs-shared
{:cljsbuild
{:builds
{:main
{:compiler
{:closure-defines {looped-in.analytics/amplitude-api-key
"<your API key>"}}}}}}]
```
Then run `lein cljsbuild once` to rebuild the extension with the new API key (you may need to first delete `ext/js/generated` to force a fresh build).
## License
Copyright © 2018 Jeremy Dormitzer

View File

@ -1,61 +0,0 @@
;; Copyright © 2018 Jeremy Dormitzer
;;
;; This file is part of Looped In.
;;
;; Looped In is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Looped In is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Looped In. If not, see <http://www.gnu.org/licenses/>.
(ns looped-in.analytics
(:require [goog.dom :as dom]
[cljs.core.async :refer [go chan <! >!]]
[looped-in.promises :refer [promise->channel]]
[looped-in.logging :as log]))
(goog-define amplitude-api-key "FAKE_API_KEY")
(def amplitude-init-code
(str "(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement('script');r.type='text/javascript';r.async=true;r.src='https://cdn.amplitude.com/libs/amplitude-4.1.0-min.gz.js';r.onload=function(){if(e.amplitude.runQueuedFunctions){e.amplitude.runQueuedFunctions()}else{console.log('[Amplitude] Error: could not load SDK')}};var i=t.getElementsByTagName('script')[0];i.parentNode.insertBefore(r,i);function s(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));return this}}var o=function(){this._q=[];return this};var a=['add','append','clearAll','prepend','set','setOnce','unset'];for(var u=0;u<a.length;u++){s(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this};var l=['setProductId','setQuantity','setPrice','setRevenueType','setEventProperties'];for(var p=0;p<l.length;p++){s(c,l[p])}n.Revenue=c;var d=['init','logEvent','logRevenue','setUserId','setUserProperties','setOptOut','setVersionName','setDomain','setDeviceId','setGlobalUserProperties','identify','clearUserProperties','setGroup','logRevenueV2','regenerateDeviceId','logEventWithTimestamp','logEventWithGroups','setSessionId'];function v(e){function t(t){e[t]=function(){ e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){ e=(!e||e.length===0?'$default_instance':e).toLowerCase();if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};v(n._iq[e])}return n._iq[e]} ;e.amplitude=n})(window,document);amplitude.getInstance().init('" amplitude-api-key "');"))
(defn do-not-track
"Returns true if Do Not Track is enabled"
[]
(= (.-doNotTrack js/navigator) "1"))
(defn init-amplitude
"Injects the Amplitude bootstrapping script if DNT is disabled"
[]
(when-not (do-not-track)
(dom/appendChild (.-body (dom/getDocument))
(dom/createDom "script" nil amplitude-init-code))
(go (let [user-id (-> js/browser
(.-runtime)
(.sendMessage (clj->js {:type "getUserId"}))
(promise->channel)
(<!))]
(.setUserId (.getInstance js/amplitude) user-id)))))
(defn log-event
"Logs an event to Amplitude. Returns a channel that resolves with the response from Amplitude"
([event-name properties]
(let [res-channel (chan)]
(when (not (do-not-track))
(if-not (exists? js/amplitude)
(log/error "Unable to get Amplitude instance. Did you call init-amplitude?")
(.logEvent (.getInstance js/amplitude)
event-name
(clj->js properties)
(fn [response-code response-body]
(go (>! res-channel {:code response-code
:body response-body}))))))
res-channel))
([event-name] (log-event event-name nil)))

View File

@ -20,7 +20,6 @@
[ajax.core :refer [GET]]
[goog.string :as gstring]
[looped-in.hackernews :as hn]
[looped-in.analytics :as analytics]
[looped-in.logging :as log]
[looped-in.promises :refer [channel->promise promise->channel]]))
@ -103,8 +102,7 @@
"hits" (channel->promise (go @hits))
"fetchItem" (channel->promise
(go (clj->js (<! (hn/fetch-item (.-id msg))))))
"getUserId" (channel->promise (get-user-id))
"logEvent" (analytics/log-event (.-eventType msg) (.-eventProperties msg))))
"getUserId" (channel->promise (get-user-id))))
(-> js/browser
(.-tabs)
@ -125,5 +123,3 @@
(.-runtime)
(.-onMessage)
(.addListener handle-message))
(analytics/init-amplitude)

View File

@ -19,7 +19,6 @@
(:require [goog.dom :as dom]
[goog.events :as events]
[goog.style :as style]
[looped-in.analytics :as analytics]
[looped-in.logging :as log]))
(def sidebar-width 300)
@ -52,8 +51,6 @@
(defn close-sidebar []
(let [$html (.-documentElement js/document)
$sidebar (dom/getElement "loopedInSidebar")]
(-> js/browser (.-runtime) (.sendMessage (clj->js {:type "logEvent"
:eventType "CLOSED_SIDEBAR"})))
(dom/removeNode $sidebar)
(set! (-> $html (.-style) (.-paddingLeft)) @old-html-padding)))

View File

@ -22,8 +22,7 @@
[looped-in.hackernews :as hn]
[looped-in.components :as components]
[looped-in.promises :refer [promise->channel]]
[looped-in.logging :as log]
[looped-in.analytics :as analytics]))
[looped-in.logging :as log]))
(enable-console-print!)
@ -118,13 +117,7 @@
"div"
"storyHeader"
(components/body30 (:title current-item))
(components/with-listener
(components/item-link (:id current-item))
"click"
(fn [e]
(analytics/log-event
"CLICKED_HN_EXTERNAL_LINK"
{:type "story"}))))
(components/item-link (:id current-item)))
(components/story-caption (:points current-item)
(:author current-item)
(* (:created_at_i current-item) 1000)))
@ -135,13 +128,7 @@
(components/comment-caption (:author current-item)
(* (:created_at_i current-item)
1000))
(components/with-listener
(components/item-link (:id current-item))
"click"
(fn [e]
(analytics/log-event
"CLICKED_HN_EXTERNAL_LINK"
{:type "comment"}))))
(components/item-link (:id current-item)))
(components/comment-text (:text current-item))))
(map-indexed (fn [index child]
(-> (components/card
@ -151,13 +138,7 @@
(components/comment-caption
(:author child)
(* (:created_at_i child) 1000))
(components/with-listener
(components/item-link (:id child))
"click"
(fn [e]
(analytics/log-event
"CLICKED_HN_EXTERNAL_LINK"
{:type "comment"}))))
(components/item-link (:id child)))
(components/comment-text (:text child))
(-> (components/replies-indicator
(count (:children child)))
@ -168,9 +149,6 @@
(components/with-listener
"click"
(fn [e]
(analytics/log-event
"CLICKED_HN_VIEW_COMMENTS"
{:depth (count (:depth state))})
(dispatch-message
{:type :enq-depth
:index index}))))
@ -195,13 +173,7 @@
"div"
"storyHeader"
(components/body30 (:title hit))
(components/with-listener
(components/item-link (:objectID hit))
"click"
(fn [e]
(analytics/log-event
"CLICKED_HN_EXTERNAL_LINK"
{:type "story"}))))
(components/item-link (:objectID hit)))
(components/story-caption (:points hit)
(:author hit)
(* (:created_at_i hit) 1000))
@ -213,7 +185,6 @@
(components/with-listener
"click"
(fn [e]
(analytics/log-event "CLICKED_HN_STORY")
(dispatch-message {:type :loading :loading true})
(go
(-> (fetch-item (:objectID hit))
@ -251,7 +222,6 @@
(events/listen (dom/getElement "backButton")
"click"
(fn [e]
(analytics/log-event "CLICKED_BACK_BUTTON" {:depth (count (:depth state))})
(let [depth (:depth state)]
(if (> (count depth) 0)
(dispatch-message {:type :deq-depth})
@ -283,8 +253,6 @@
[]
(let [initial-state (update-state {:type :loading :loading true} (model))]
(run-render-loop initial-state)
(analytics/init-amplitude)
(analytics/log-event "OPENED_SIDEBAR")
(go (-> (fetch-hits)
(<!)
(#(update-state {:type :got-hits