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
26 changes: 18 additions & 8 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ var constructor = function () {
return replaceOtherWithEmailsha256(userIdentities);
}

function returnLocalSessionAttributes() {
if (
isEmpty(self.placementEventMappingLookup) ||
!window.mParticle.Rokt ||
typeof window.mParticle.Rokt.getLocalSessionAttributes !==
'function'
) {
return {};
}
return window.mParticle.Rokt.getLocalSessionAttributes();
}

function replaceOtherWithEmailsha256(_data) {
var data = mergeObjects({}, _data || {});
if (_data.hasOwnProperty(OTHER_IDENTITY)) {
Expand Down Expand Up @@ -211,14 +223,7 @@ var constructor = function () {

var filteredUserIdentities = returnUserIdentities(filteredUser);

var localSessionAttributes = {};

try {
localSessionAttributes =
window.mParticle.Rokt.getLocalSessionAttributes();
} catch (error) {
console.error('Error getting local session attributes:', error);
}
var localSessionAttributes = returnLocalSessionAttributes();

var selectPlacementsAttributes = mergeObjects(
filteredUserIdentities,
Expand Down Expand Up @@ -256,6 +261,7 @@ var constructor = function () {
function processEvent(event) {
if (
!isKitReady() ||
isEmpty(self.placementEventMappingLookup) ||
Comment thread
alexs-mparticle marked this conversation as resolved.
typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
) {
return;
Expand Down Expand Up @@ -494,6 +500,10 @@ function hashEventMessage(messageType, eventType, eventName) {
);
}

function isEmpty(value) {
return value == null || !(Object.keys(value) || value).length;
Comment thread
alexs-mparticle marked this conversation as resolved.
}

if (window && window.mParticle && window.mParticle.addForwarder) {
window.mParticle.addForwarder({
name: name,
Expand Down
46 changes: 46 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,14 @@ describe('Rokt Forwarder', () => {
await window.mParticle.forwarder.init(
{
accountId: '123456',
placementEventMapping: JSON.stringify([
{
jsmap: 'test-event-hash',
map: 'test-event-map',
maptype: 'EventClass.Id',
value: 'test-mapped-flag',
},
]),
},
reportService.cb,
true
Expand All @@ -743,6 +751,44 @@ describe('Rokt Forwarder', () => {
},
});
});

it('should not throw an error if getLocalSessionAttributes is not available', async () => {
let errorLogged = false;
const originalConsoleError = console.error;
console.error = function (message) {
if (
message &&
message.indexOf &&
message.indexOf(
'Error getting local session attributes'
) !== -1
) {
errorLogged = true;
}
originalConsoleError.apply(console, arguments);
};

delete window.mParticle.Rokt.getLocalSessionAttributes;

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

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {
'test-attribute': 'test-value',
},
});

errorLogged.should.equal(false);

console.error = originalConsoleError;
});
});

describe('User Attributes', () => {
Expand Down