Skip to content

Commit b7a78c6

Browse files
committed
add helper method to fetch sessionId
1 parent 8851628 commit b7a78c6

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
* Add getSessionId helper method to fetch the current sessionId.
4+
35
## 2.7.0 (December 1, 2015)
46

57
* If cookies are disabled by user, then fallback to localstorage to save the cookie data.

amplitude.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ Amplitude.prototype.isNewSession = function() {
290290
return this._newSession;
291291
};
292292

293+
Amplitude.prototype.getSessionId = function() {
294+
return this._sessionId;
295+
};
296+
293297
Amplitude.prototype.nextEventId = function() {
294298
this._eventId++;
295299
return this._eventId;

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ Amplitude.prototype.isNewSession = function() {
184184
return this._newSession;
185185
};
186186

187+
Amplitude.prototype.getSessionId = function() {
188+
return this._sessionId;
189+
};
190+
187191
Amplitude.prototype.nextEventId = function() {
188192
this._eventId++;
189193
return this._eventId;

test/amplitude.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,6 @@ describe('Amplitude', function() {
12881288
amplitude2.setUserProperties({'key':'value'}); // identify event at time 30
12891289

12901290
var cookieData = JSON.parse(localStorage.getItem('amp_cookiestore_amplitude_id'));
1291-
console.log(cookieData);
12921291
assert.deepEqual(cookieData, {
12931292
'deviceId': deviceId,
12941293
'userId': null,
@@ -1623,6 +1622,16 @@ describe('Amplitude', function() {
16231622
assert.notEqual(amplitude._sessionId, sessionId);
16241623
assert.equal(events[0].session_id, amplitude._sessionId);
16251624
});
1625+
1626+
it('should be fetched correctly by getSessionId', function() {
1627+
var timestamp = 1000;
1628+
clock.tick(timestamp);
1629+
var amplitude2 = new Amplitude();
1630+
amplitude2.init(apiKey);
1631+
assert.equal(amplitude2._sessionId, timestamp);
1632+
assert.equal(amplitude2.getSessionId(), timestamp);
1633+
assert.equal(amplitude2.getSessionId(), amplitude2._sessionId);
1634+
});
16261635
});
16271636

16281637
describe('truncate', function() {

0 commit comments

Comments
 (0)