Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Add support for passing callback function to identify.
* Add support for prepend user property operation.
* Keeping sessions and event metadata in sync across multiple windows/tabs.

### 2.9.1 (March 6, 2016)

Expand Down
1 change: 1 addition & 0 deletions amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperti
callback = null;
}

_loadCookieData(this);
if (!eventType || this.options.optOut) {
if (callback) {
callback(0, 'No request sent');
Expand Down
2 changes: 1 addition & 1 deletion amplitude.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperti
callback = null;
}

_loadCookieData(this);
if (!eventType || this.options.optOut) {
if (callback) {
callback(0, 'No request sent');
Expand Down
25 changes: 25 additions & 0 deletions test/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,31 @@ describe('Amplitude', function() {
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
});
});

it('should synchronize event data across multiple amplitude instances that share the same cookie', function() {
// this test fails if logEvent does not reload cookie data every time
var amplitude1 = new Amplitude();
amplitude1.init(apiKey, null, {batchEvents: true, eventUploadThreshold: 5});
var amplitude2 = new Amplitude();
amplitude2.init(apiKey, null, {batchEvents: true, eventUploadThreshold: 5});

amplitude1.logEvent('test1');
amplitude2.logEvent('test2');
amplitude1.logEvent('test3');
amplitude2.logEvent('test4');
amplitude2.identify(new amplitude2.Identify().set('key', 'value'));
amplitude1.logEvent('test5');

// the event ids should all be sequential since amplitude1 and amplitude2 have synchronized cookies
var eventId = amplitude1._unsentEvents[0]['event_id'];
assert.equal(amplitude2._unsentEvents[0]['event_id'], eventId + 1);
assert.equal(amplitude1._unsentEvents[1]['event_id'], eventId + 2);
assert.equal(amplitude2._unsentEvents[1]['event_id'], eventId + 3);

var sequenceNumber = amplitude1._unsentEvents[0]['sequence_number'];
assert.equal(amplitude2._unsentIdentifys[0]['sequence_number'], sequenceNumber + 4);
assert.equal(amplitude1._unsentEvents[2]['sequence_number'], sequenceNumber + 5);
});
});

describe('optOut', function() {
Expand Down