Begin analytics.cljs; add secure api token handling
This commit is contained in:
parent
a5febca9ce
commit
99ddcb33e3
3
.gitignore
vendored
3
.gitignore
vendored
@ -10,4 +10,5 @@ pom.xml.asc
|
||||
.hgignore
|
||||
.hg/
|
||||
ext/js/generated/
|
||||
.cljs_rhino_repl
|
||||
.cljs_rhino_repl
|
||||
profiles.clj
|
32
project.clj
32
project.clj
@ -9,20 +9,22 @@
|
||||
[org.clojure/core.match "0.3.0-alpha5"]
|
||||
[cljs-ajax "0.7.3"]]
|
||||
:plugins [[lein-cljsbuild "1.1.7"]]
|
||||
:cljsbuild {:builds [{:source-paths ["src"]
|
||||
:compiler {:optimizations :simple
|
||||
:pretty-print true
|
||||
:source-map true
|
||||
:output-dir "ext/js/generated/out"
|
||||
:modules {:background
|
||||
{:output-to "ext/js/generated/background.js"
|
||||
:entries #{"looped-in.background"}}
|
||||
:content
|
||||
{:output-to "ext/js/generated/content.js"
|
||||
:entries #{"looped-in.content"}}
|
||||
:sidebar
|
||||
{:output-to "ext/js/generated/sidebar.js"
|
||||
:entries #{"looped-in.sidebar"}}}}}]}
|
||||
:profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.2"]
|
||||
:profiles {:cljs-shared
|
||||
{:cljsbuild
|
||||
{:builds [{:source-paths ["src"]
|
||||
:compiler {:optimizations :simple
|
||||
:pretty-print true
|
||||
:source-map true
|
||||
:output-dir "ext/js/generated/out"
|
||||
:modules {:background
|
||||
{:output-to "ext/js/generated/background.js"
|
||||
:entries #{"looped-in.background"}}
|
||||
:content
|
||||
{:output-to "ext/js/generated/content.js"
|
||||
:entries #{"looped-in.content"}}
|
||||
:sidebar
|
||||
{:output-to "ext/js/generated/sidebar.js"
|
||||
:entries #{"looped-in.sidebar"}}}}}]}}
|
||||
:dev {:dependencies [[com.cemerick/piggieback "0.2.2"]
|
||||
[org.clojure/tools.nrepl "0.2.10"]]
|
||||
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}})
|
||||
|
20
src/looped_in/analytics.cljs
Normal file
20
src/looped_in/analytics.cljs
Normal file
@ -0,0 +1,20 @@
|
||||
(ns looped-in.analytics
|
||||
(:require [goog.html.SafeScript :as SafeScript]
|
||||
[goog.string.Const :as Const]))
|
||||
|
||||
(goog-define amplitude-api-key "FAKE_API_KEY")
|
||||
(def amplitude-init-code
|
||||
"function(apiKey) {(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(apiKey);}")
|
||||
|
||||
(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))
|
||||
(let [script (SafeScript/fromConstantAndArgs
|
||||
(Const/from amplitude-init-code)
|
||||
amplitude-api-key)])))
|
Loading…
Reference in New Issue
Block a user