Skip to content

Commit 360d285

Browse files
committedJan 25, 2019
add support for the page method
1 parent abd0078 commit 360d285

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎src/circleci/analytics_clj/core.clj

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
GroupMessage
88
IdentifyMessage
99
ScreenMessage
10-
TrackMessage)))
10+
TrackMessage
11+
PageMessage)))
1112

1213
(def ^:private ctx {"library" {"name" "analytics-clj"
13-
"version" "0.4.2"}})
14+
"version" "0.5.0"}})
1415

1516
(defn initialize
1617
"Start building an Analytics instance."
@@ -143,6 +144,24 @@
143144
(common-fields (merge {:user-id user-id} options))
144145
(cond-> (not (nil? properties)) (properties* (string-keys properties)))))))
145146

147+
(defn page
148+
"The `page` method lets you record whenever a user
149+
sees a page of your website, along with optional
150+
extra information about the page being viewed."
151+
152+
{:added "0.5.0"}
153+
154+
([^Analytics analytics user-id name]
155+
(page analytics user-id name nil nil))
156+
157+
([^Analytics analytics user-id name properties]
158+
(page analytics user-id name properties nil))
159+
160+
([^Analytics analytics user-id name properties options]
161+
(enqueue analytics (doto (PageMessage/builder name)
162+
(common-fields (merge {:user-id user-id} options))
163+
(cond-> (not (nil? properties)) (properties* (string-keys properties)))))))
164+
146165
(defn group
147166
"`group` lets you associate an identified user with
148167
a group. A group could be a company, organization, account,

‎test/circleci/analytics_clj/core_test.clj

+13
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@
111111
(a/screen analytics "1234" "Login Screen" {:path "/users/login"})
112112
(is @called)))))
113113

114+
(deftest test-page
115+
(testing "a simple page call"
116+
(a/page analytics "1234" "Login Page"))
117+
118+
(testing "a apge call with custom properties"
119+
(let [called (atom false)]
120+
(with-redefs [e/properties* (fn [mb properties]
121+
(is (= "path" (-> properties keys first)))
122+
(is (= "/users/login" (-> properties vals first)))
123+
(reset! called true))]
124+
(a/page analytics "1234" "Login Page" {:path "/users/login"})
125+
(is @called)))))
126+
114127
(deftest test-group
115128
(let [called (atom false)]
116129
(with-redefs [e/traits* (fn [mb traits]

0 commit comments

Comments
 (0)
Failed to load comments.