-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitialization.js
More file actions
95 lines (90 loc) · 3.84 KB
/
initialization.js
File metadata and controls
95 lines (90 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var roktLauncherScript = 'https://apps.rokt.com/wsdk/integrations/launcher.js';
var initialization = {
name: 'RoktWsdk',
moduleId: 181,
/* ****** Fill out initForwarder to load your SDK ******
Note that not all arguments may apply to your SDK initialization.
These are passed from mParticle, but leave them even if they are not being used.
forwarderSettings contain settings that your SDK requires in order to initialize
userAttributes example: {gender: 'male', age: 25}
userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: 'emailid@email.com' }
additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
*/
initForwarder: function (
forwarderSettings,
testMode,
_userAttributes,
_userIdentities,
processEvent,
eventQueue,
_isInitialized,
_common,
_appVersion,
_appName,
_customFlags,
_clientId
) {
if (!testMode) {
if (!window.Rokt || !(window.Rokt && window.Rokt.currentLauncher)) {
var target = document.head || document.body;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = roktLauncherScript;
script.async = true;
script.crossOrigin = 'anonymous';
script.fetchPriority = 'high';
script.id = 'rokt-launcher';
script.onload = function () {
// Once the script loads, ensure the Rokt object is available
if (
window.Rokt &&
typeof window.Rokt.createLauncher === 'function' &&
window.Rokt.currentLauncher === undefined
) {
window.Rokt.createLauncher({
accountId: forwarderSettings.accountId,
sandbox: forwarderSettings.sandboxMode === 'True'
})
.then(function (launcher) {
// Assign the launcher to a global variable for later access
window.Rokt.currentLauncher = launcher;
if (window['Rokt'] && eventQueue.length > 0) {
for (
var i = 0;
i < eventQueue.length;
i++
) {
processEvent(eventQueue[i]);
}
eventQueue = [];
}
})
.catch(function (err) {
console.error(
'Error creating Rokt launcher:',
err
);
});
} else {
console.error(
'Rokt object is not available after script load.'
);
}
};
script.onerror = function (error) {
console.error(
'Failed to load Rokt launcher script:',
error
);
};
target.appendChild(script);
} else {
// For testing, you can simulate initialization if needed.
console.log(
'Test mode enabled – skipping Rokt launcher script load.'
);
}
}
},
};
module.exports = initialization;