Skip to content

Commit

Permalink
Parse query params for referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Jul 16, 2020
1 parent add174a commit 48b62b5
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/status_im/acquisition/core.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.acquisition.core
(:require [re-frame.core :as re-frame]
(:require [clojure.string :as cstr]
[re-frame.core :as re-frame]
[reagent.ratom :refer [make-reaction]]
[status-im.utils.fx :as fx]
[status-im.ethereum.json-rpc :as json-rpc]
Expand All @@ -25,6 +26,31 @@
(str (get acquisition-routes :clicks) "/" referral)
(get acquisition-routes :registrations)))

(defn- split-param [param]
(->
(cstr/split param #"=")
(concat (repeat ""))
(->>
(take 2))))

(defn- url-decode
[string]
(some-> string str (cstr/replace #"\+" "%20") (js/decodeURIComponent)))

(defn- query->map
[qstr]
(when-not (cstr/blank? qstr)
(some->> (cstr/split qstr #"&")
seq
(mapcat split-param)
(map url-decode)
(apply hash-map))))

(defn parse-referrer
"Google return query params for referral with all utm tags"
[referrer]
(-> referrer query->map (get "referrer")))

(def referrer-decision-key "referrer-decision")

(fx/defn handle-error
Expand Down Expand Up @@ -73,9 +99,9 @@
(re-frame/dispatch [::has-referrer data external-referrer])
(-> (getInstallReferrer)
(.then (fn [install-referrer]
(when (and (seq install-referrer)
(when (and (seq (parse-referrer install-referrer))
(not= install-referrer "unknown"))
(re-frame/dispatch [::has-referrer data install-referrer])))))))))
(re-frame/dispatch [::has-referrer data (parse-referrer install-referrer)])))))))))
(.catch (fn [error]
(log/error "[async-storage]" error))))))

Expand Down

0 comments on commit 48b62b5

Please sign in to comment.