Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,10 @@ var constructor = function () {

function _sendEventStream(event) {
if (window.Rokt && typeof window.Rokt.__event_stream__ === 'function') {
window.Rokt.__event_stream__(event);
var enrichedEvent = mergeObjects({}, event, {
UserAttributes: self.userAttributes,
});
window.Rokt.__event_stream__(enrichedEvent);
}
}

Expand Down
128 changes: 127 additions & 1 deletion test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4647,7 +4647,11 @@
window.mParticle.forwarder.process(testEvent);

receivedEvents.length.should.equal(1);
receivedEvents[0].should.deepEqual(testEvent);
receivedEvents[0].EventName.should.equal('Test Event');
receivedEvents[0].EventCategory.should.equal(EventType.Other);
receivedEvents[0].EventDataType.should.equal(

Check failure on line 4652 in test/src/tests.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Replace `⏎················MessageType.PageEvent⏎············` with `MessageType.PageEvent`
MessageType.PageEvent
);
});

it('should not throw when window.Rokt.__event_stream__ is not defined', async () => {
Expand Down Expand Up @@ -4833,6 +4837,128 @@
'foo-mapped-flag': true,
});
});

it('should enrich event with Kit userAttributes before forwarding', async () => {
var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
true,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

window.mParticle.forwarder.setUserAttribute('email', 'test@example.com');

Check failure on line 4857 in test/src/tests.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Replace `'email',·'test@example.com'` with `⏎················'email',⏎················'test@example.com'⏎············`
window.mParticle.forwarder.setUserAttribute('plan', 'premium');

window.mParticle.forwarder.process({
EventName: 'Page View',
EventCategory: EventType.Navigation,
EventDataType: MessageType.PageView,
});

receivedEvents.length.should.equal(1);
receivedEvents[0].UserAttributes.should.deepEqual({
email: 'test@example.com',
plan: 'premium',
});
receivedEvents[0].EventName.should.equal('Page View');
});

it('should use Kit userAttributes over event-level UserAttributes', async () => {
var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
true,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

window.mParticle.forwarder.setUserAttribute('email', 'fresh@example.com');

Check failure on line 4890 in test/src/tests.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Replace `'email',·'fresh@example.com'` with `⏎················'email',⏎················'fresh@example.com'⏎············`

window.mParticle.forwarder.process({
EventName: 'Test',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
UserAttributes: { email: 'stale@example.com' },
});

receivedEvents.length.should.equal(1);
receivedEvents[0].UserAttributes.email.should.equal(
'fresh@example.com'
);
});

it('should not mutate the original event object', async () => {
var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
true,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

window.mParticle.forwarder.setUserAttribute('key', 'value');

var originalEvent = {
EventName: 'Original',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
};

window.mParticle.forwarder.process(originalEvent);

(originalEvent.UserAttributes === undefined).should.equal(true);
receivedEvents[0].UserAttributes.should.deepEqual({ key: 'value' });
});

it('should send empty UserAttributes when Kit has no user attributes', async () => {
var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
true,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

window.mParticle.forwarder.userAttributes = {};

window.mParticle.forwarder.process({
EventName: 'Test',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
});

receivedEvents.length.should.equal(1);
receivedEvents[0].UserAttributes.should.deepEqual({});
});
});

describe('#_setRoktSessionId', () => {
Expand Down
Loading