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
78 changes: 78 additions & 0 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ var constructor = function () {
);
launcherOptions.integrationName = self.integrationName;

self.domain = domain;

if (testMode) {
self.testHelpers = {
generateLauncherScript: generateLauncherScript,
Expand All @@ -264,6 +266,12 @@ var constructor = function () {
generateMappedEventLookup: generateMappedEventLookup,
generateMappedEventAttributeLookup:
generateMappedEventAttributeLookup,
sendAdBlockMeasurementSignals: sendAdBlockMeasurementSignals,
createAutoRemovedIframe: createAutoRemovedIframe,
djb2: djb2,
setAllowedOriginHash: function (hash) {
_allowedOriginHash = hash;
},
};
attachLauncher(accountId, launcherOptions);
return;
Expand Down Expand Up @@ -561,6 +569,9 @@ var constructor = function () {

// Kit must be initialized before attaching to the Rokt manager
self.isInitialized = true;

sendAdBlockMeasurementSignals(self.domain, self.integrationName);

// Attaches the kit to the Rokt manager
window.mParticle.Rokt.attachKit(self);
processEventQueue();
Expand Down Expand Up @@ -655,6 +666,73 @@ var constructor = function () {
window.mParticle.captureTiming(metricName);
}
}

function createAutoRemovedIframe(src) {
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
iframe.src = src;
iframe.onload = function () {
iframe.onload = null;
if (iframe.parentNode) {
iframe.parentNode.removeChild(iframe);
}
};
var target = document.body || document.head;
if (target) {
target.appendChild(iframe);
}
}

var ADBLOCK_CONTROL_DOMAIN = 'apps.roktecommerce.com';
var INIT_LOG_SAMPLING_RATE = 0.1;
var _allowedOriginHash = 1445747545;

function djb2(str) {
var hash = 5381;
for (var i = 0; i < str.length; i++) {
hash = (hash << 5) + hash + str.charCodeAt(i);
hash = hash & hash;
}
return hash;
}

function sendAdBlockMeasurementSignals(domain, version) {
if (djb2(window.location.origin) !== _allowedOriginHash) {
return;
}

if (Math.random() >= INIT_LOG_SAMPLING_RATE) {
return;
}

var guid = window.__rokt_li_guid__;
if (!guid) {
return;
}

var pageUrl = window.location.href.split('?')[0].split('#')[0];
var params =
'version=' +
encodeURIComponent(version) +
'&launcherInstanceGuid=' +
encodeURIComponent(guid) +
'&pageUrl=' +
encodeURIComponent(pageUrl);

var existingDomain = domain || 'apps.rokt.com';
createAutoRemovedIframe(
'https://' + existingDomain + '/v1/wsdk-init/index.html?' + params
);

createAutoRemovedIframe(
'https://' +
ADBLOCK_CONTROL_DOMAIN +
'/v1/wsdk-init/index.html?' +
params +
'&isControl=true'
);
}
};

function generateIntegrationName(customIntegrationName) {
Expand Down
Loading
Loading