Skip to content

Commit 8ccfd54

Browse files
Address PR Comments
1 parent a1659eb commit 8ccfd54

2 files changed

Lines changed: 31 additions & 40 deletions

File tree

src/Rokt-Kit.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var VNEXT_EXTENSIONS = {
2525

2626
var constructor = function () {
2727
var self = this;
28-
var roktLauncherScript = '';
2928

3029
self.name = name;
3130
self.moduleId = moduleId;
@@ -50,6 +49,13 @@ var constructor = function () {
5049
return baseUrl + '?extensions=' + extensions.join(',');
5150
}
5251

52+
/**
53+
* Passes attributes to the Rokt Web SDK for client-side hashing
54+
* @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
55+
* @param {Object} attributes - The attributes to be hashed
56+
* @returns {Promise<Object|null>} A Promise resolving to the
57+
* hashed attributes from the launcher, or `null` if the kit is not initialized
58+
*/
5359
function hashAttributes(attributes) {
5460
if (!isInitialized()) {
5561
console.error('Rokt Kit: Not initialized');
@@ -66,16 +72,15 @@ var constructor = function () {
6672
filteredUserAttributes
6773
) {
6874
var accountId = settings.accountId;
75+
var vNextExtensions = extractvNextExtensions(settings.vNextExtensions);
6976
self.userAttributes = filteredUserAttributes;
7077
self.onboardingExpProvider = settings.onboardingExpProvider;
71-
self.vNextExtensions = extractvNextExtensions(settings.vNextExtensions);
72-
73-
roktLauncherScript = generateLauncherScript(self.vNextExtensions);
7478

7579
if (testMode) {
7680
// Initialize test helpers only in test mode
7781
self.testHelpers = {
7882
generateLauncherScript: generateLauncherScript,
83+
extractvNextExtensions: extractvNextExtensions,
7984
};
8085
attachLauncher(accountId);
8186
return;
@@ -85,7 +90,7 @@ var constructor = function () {
8590
var target = document.head || document.body;
8691
var script = document.createElement('script');
8792
script.type = 'text/javascript';
88-
script.src = roktLauncherScript;
93+
script.src = generateLauncherScript(vNextExtensions);
8994
script.async = true;
9095
script.crossOrigin = 'anonymous';
9196
script.fetchPriority = 'high';
@@ -188,9 +193,6 @@ var constructor = function () {
188193
return;
189194
}
190195

191-
// TODO: Should we check if select placements has been called?
192-
// Some extensions seem to need that to happen first
193-
// TODO: Should we attach the Rokt SDK to the kit as well?
194196
window.Rokt.setExtensionData(partnerExtensionData);
195197
}
196198

@@ -243,6 +245,7 @@ var constructor = function () {
243245
window.mParticle.Rokt.attachKit(self);
244246

245247
self.isInitialized = true;
248+
console.warn('Rokt TRACE: launcher called');
246249
})
247250
.catch(function (err) {
248251
console.error('Error creating Rokt launcher:', err);

test/src/tests.js

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -819,45 +819,33 @@ describe('Rokt Forwarder', () => {
819819

820820
describe('extractvNextExtensions', () => {
821821
it('should correctly map known extension names to their query parameters', async () => {
822-
await mParticle.forwarder.init(
823-
{
824-
accountId: '123456',
825-
vNextExtensions:
826-
'[{&quot;value&quot;:&quot;Coupon on Signup Extension Detection&quot;},' +
822+
window.mParticle.forwarder.testHelpers
823+
.extractvNextExtensions(
824+
'[{&quot;value&quot;:&quot;Coupon on Signup Extension Detection&quot;},' +
827825
'{&quot;value&quot;:&quot;Experiment Monitoring&quot;},' +
828826
'{&quot;value&quot;:&quot;Sponsored Payments Apple Pay&quot;},' +
829-
'{&quot;value&quot;:&quot;Realtime Conversion Promotion&quot;}]',
830-
},
831-
reportService.cb,
832-
true
833-
);
834-
835-
window.mParticle.forwarder.vNextExtensions.should.deepEqual([
836-
'cos-extension-detection',
837-
'experiment-monitoring',
838-
'sponsored-payments-apple-pay',
839-
'realtime-conversion-promotion',
840-
]);
827+
'{&quot;value&quot;:&quot;Realtime Conversion Promotion&quot;}]'
828+
)
829+
.should.deepEqual([
830+
'cos-extension-detection',
831+
'experiment-monitoring',
832+
'sponsored-payments-apple-pay',
833+
'realtime-conversion-promotion',
834+
]);
841835
});
842836

843837
it('should ignore unknown or invalid extensions', async () => {
844-
await mParticle.forwarder.init(
845-
{
846-
accountId: '123456',
847-
vNextExtensions:
848-
'[{&quot;value&quot;:&quot;Unknown Extension&quot;},' +
838+
window.mParticle.forwarder.testHelpers
839+
.extractvNextExtensions(
840+
'[{&quot;value&quot;:&quot;Unknown Extension&quot;},' +
849841
'{&quot;value&quot;:&quot;Experiment Monitoring&quot;},' +
850842
'{&quot;invalid_key&quot;:&quot;Invalid Format&quot;},' +
851-
'{&quot;value&quot;:&quot;Sponsored Payments Apple Pay&quot;}]',
852-
},
853-
reportService.cb,
854-
true
855-
);
856-
857-
window.mParticle.forwarder.vNextExtensions.should.deepEqual([
858-
'experiment-monitoring',
859-
'sponsored-payments-apple-pay',
860-
]);
843+
'{&quot;value&quot;:&quot;Sponsored Payments Apple Pay&quot;}]'
844+
)
845+
.should.deepEqual([
846+
'experiment-monitoring',
847+
'sponsored-payments-apple-pay',
848+
]);
861849
});
862850
});
863851
});

0 commit comments

Comments
 (0)