Skip to content
Closed
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
33 changes: 33 additions & 0 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var constructor = function () {
) {
var accountId = settings.accountId;
var sandboxMode = settings.sandboxMode === 'True';
self.onboardingExpProvider = settings.onboardingExpProvider;

self.userAttributes = _userAttributes;

Expand Down Expand Up @@ -77,6 +78,9 @@ var constructor = function () {

// Attaches the kit to the Rokt manager
window.mParticle.Rokt.kit = self;

console.log("Rokt launcher attached");

})
.catch(function (err) {
console.error('Error creating Rokt launcher:', err);
Expand All @@ -99,9 +103,13 @@ var constructor = function () {
}

function selectPlacements(options) {

const optimizelyAttributes = fetchOptimizely() ? (self.onboardingExpProvider && self.onboardingExpProvider === 'Optimizely') : {};

const placementAttributes = {
...options?.attributes,
...self.userAttributes,
...optimizelyAttributes,
};

const userAttributeFilters = self.filters.userAttributeFilters;
Expand Down Expand Up @@ -133,6 +141,31 @@ var constructor = function () {
this.selectPlacements = selectPlacements;

// mParticle Kit Callback Methods
function fetchOptimizely() {
const forwarders = window.mParticle._getActiveForwarders().filter(function (forwarder) {
return forwarder.name === 'Optimizely';
});

try {
if (forwarders.length > 0) {
// Get the state object
var optimizelyState = window.optimizely.get('state');
// Get active experiment IDs
var activeExperimentIds = optimizelyState.getActiveExperimentIds();
// Get variations for each active experiment
var activeExperiments = activeExperimentIds.reduce(function(acc, expId) {
acc[`rokt.custom.optimizely.${expId}.variationId`] = optimizelyState.getVariationMap()[expId].id;
return acc;
}, {});

console.log("[ROKT] Active Optimizely Experiments:", activeExperiments);
return activeExperiments;
}
} catch (error) {
console.error('Error fetching Optimizely attributes:', error);
}
return {};
}
this.init = initForwarder;
this.setUserAttribute = setUserAttribute;
this.onUserIdentified = onUserIdentified;
Expand Down
Loading