Skip to content

Commit ab3ed73

Browse files
committed
Merge pull request #3 from Driftt/test-identify-on-page
add a test that identify() gets called on page load
2 parents e616d72 + d471a74 commit ab3ed73

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ lint: node_modules
7070
# Test locally in PhantomJS.
7171
test-phantomjs: node_modules build.js
7272
@$(DUOT) phantomjs $(TESTS_DIR) args: \
73-
--ignore-ssl-errors=true --path node_modules/.bin/phantomjs
73+
--ignore-ssl-errors=true --ssl-protocol=tlsv1 --path node_modules/.bin/phantomjs
7474
.PHONY: test-phantomjs
7575

7676
# Test locally in the browser.

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ function convertDate(date) {
103103
*/
104104

105105
Drift.prototype.page = function(page) {
106-
if (!this.identified && page.userId()) {
107-
window.drift.identify(page.userId());
106+
var userId = this.analytics.user().id();
107+
if (!this.identified && userId) {
108+
window.drift.identify(userId);
108109
this.identified = true;
109110
}
110111

test/index.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,43 @@ describe('Drift', function() {
106106
analytics.called(window.drift.track, 'event', { date: Math.floor(date / 1000) });
107107
});
108108
});
109+
110+
describe('#page', function() {
111+
beforeEach(function() {
112+
analytics.stub(window.drift, 'page');
113+
analytics.stub(window.drift, 'identify');
114+
});
115+
116+
it('should send a page view event but not an identify event', function() {
117+
// track a page view
118+
analytics.page('page');
119+
120+
analytics.called(window.drift.page, 'page');
121+
analytics.didNotCall(window.drift.identify);
122+
});
123+
124+
it('should send an page view event but only one identify event', function() {
125+
// set the user id by calling identify
126+
analytics.identify('id');
127+
analytics.calledOnce(window.drift.identify);
128+
129+
// track a page view
130+
analytics.page('page');
131+
132+
analytics.called(window.drift.page, 'page');
133+
analytics.calledOnce(window.drift.identify);
134+
});
135+
136+
it('should send a page view event and an identify event', function() {
137+
// set the user id explicitly
138+
analytics.user().id('id');
139+
140+
// track a page view
141+
analytics.page('page');
142+
143+
analytics.called(window.drift.page, 'page');
144+
analytics.calledOnce(window.drift.identify, 'id');
145+
});
146+
});
109147
});
110148
});

0 commit comments

Comments
 (0)