From 419aa55f149c69710540fe373e2c6ce52a61e91a Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 31 Jan 2018 18:14:57 -0700 Subject: [PATCH] Inject Amplitude init script properly --- src/looped_in/analytics.cljs | 11 +++++------ src/looped_in/sidebar.cljs | 4 +++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/looped_in/analytics.cljs b/src/looped_in/analytics.cljs index 82c2a75..b7ac39c 100644 --- a/src/looped_in/analytics.cljs +++ b/src/looped_in/analytics.cljs @@ -1,10 +1,10 @@ (ns looped-in.analytics - (:require [goog.html.SafeScript :as SafeScript] - [goog.string.Const :as Const])) + (:require [goog.dom :as dom])) (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;ujs {}) amplitude-init-code)))) diff --git a/src/looped_in/sidebar.cljs b/src/looped_in/sidebar.cljs index c8b0719..062500c 100644 --- a/src/looped_in/sidebar.cljs +++ b/src/looped_in/sidebar.cljs @@ -5,7 +5,8 @@ [looped-in.hackernews :as hn] [looped-in.components :as components] [looped-in.promises :refer [promise->channel]] - [looped-in.logging :as log])) + [looped-in.logging :as log] + [looped-in.analytics :as analytics])) (enable-console-print!) @@ -233,6 +234,7 @@ (defn init "Initializes the sidebar" [] + (analytics/init-amplitude) (let [initial-state (update-state {:type :loading :loading true} (model))] (run-render-loop initial-state) (go (-> (fetch-hits)