Skip to content

Commit 15a4a88

Browse files
committed
Refactor google-analytics fn
1 parent 00e02b2 commit 15a4a88

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/codes/clj/docs/frontend/infra/analytics.cljs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns codes.clj.docs.frontend.infra.analytics
2-
(:require [codes.clj.docs.frontend.infra.system.state :as system.state]))
2+
(:require [codes.clj.docs.frontend.infra.system.state :as system.state]
3+
[clojure.string :as string]))
34

45
(defn google-tag-manager
56
[ga-tag-id]
@@ -20,8 +21,11 @@
2021
gtag('config', '" ga-tag-id "');"))
2122
(js/document.head.insertBefore script (.-nextSibling gtm-script))))
2223

24+
(defn ga-scripts
25+
[ga-tag-id]
26+
(when-not (string/blank? ga-tag-id)
27+
(let [gtm-script (google-tag-manager ga-tag-id)]
28+
(google-tag ga-tag-id gtm-script))))
29+
2330
(defn google-analytics []
24-
(let [ga-tag-id (-> @system.state/components :config :ga-tag-id)]
25-
(when (seq ga-tag-id)
26-
(let [gtm-script (google-tag-manager ga-tag-id)]
27-
(google-tag ga-tag-id gtm-script)))))
31+
(ga-scripts (-> @system.state/components :config :ga-tag-id)))

0 commit comments

Comments
 (0)