1+ var roktLauncherScript = 'https://apps.rokt.com/wsdk/integrations/launcher.js' ;
2+
13var initialization = {
2- name : 'insertSDKNameHere' ,
3- /* ****** Fill out initForwarder to load your SDK ******
4+ name : 'RoktWsdk' ,
5+ moduleId : 181 ,
6+ /* ****** Fill out initForwarder to load your SDK ******
47 Note that not all arguments may apply to your SDK initialization.
58 These are passed from mParticle, but leave them even if they are not being used.
69 forwarderSettings contain settings that your SDK requires in order to initialize
710 userAttributes example: {gender: 'male', age: 25}
811 userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: 'emailid@email .com' }
912 additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
1013*/
11- initForwarder : function ( forwarderSettings , testMode , userAttributes , userIdentities , processEvent , eventQueue , isInitialized , common , appVersion , appName , customFlags , clientId ) {
12- /* `forwarderSettings` contains your SDK specific settings such as apiKey that your customer needs in order to initialize your SDK properly */
13-
14+ initForwarder : function (
15+ forwarderSettings ,
16+ testMode ,
17+ _userAttributes ,
18+ _userIdentities ,
19+ processEvent ,
20+ eventQueue ,
21+ _isInitialized ,
22+ _common ,
23+ _appVersion ,
24+ _appName ,
25+ _customFlags ,
26+ _clientId
27+ ) {
1428 if ( ! testMode ) {
15- /* Load your Web SDK here using a variant of your snippet from your readme that your customers would generally put into their <head> tags
16- Generally, our integrations create script tags and append them to the <head>. Please follow the following format as a guide:
17- */
29+ if ( ! window . Rokt || ! ( window . Rokt && window . Rokt . currentLauncher ) ) {
30+ var target = document . head || document . body ;
31+ var script = document . createElement ( 'script' ) ;
32+ script . type = 'text/javascript' ;
33+ script . src = roktLauncherScript ;
34+ script . async = true ;
35+ script . crossOrigin = 'anonymous' ;
36+ script . fetchPriority = 'high' ;
37+ script . id = 'rokt-launcher' ;
38+
39+ script . onload = function ( ) {
40+ // Once the script loads, ensure the Rokt object is available
41+ if (
42+ window . Rokt &&
43+ typeof window . Rokt . createLauncher === 'function' &&
44+ window . Rokt . currentLauncher === undefined
45+ ) {
46+ window . Rokt . createLauncher ( {
47+ accountId : forwarderSettings . accountId ,
48+ sandbox : forwarderSettings . sandboxMode === 'True' ,
49+ } )
50+ . then ( function ( launcher ) {
51+ // Assign the launcher to a global variable for later access
52+ window . Rokt . currentLauncher = launcher ;
53+ if ( window [ 'Rokt' ] && eventQueue . length > 0 ) {
54+ for (
55+ var i = 0 ;
56+ i < eventQueue . length ;
57+ i ++
58+ ) {
59+ processEvent ( eventQueue [ i ] ) ;
60+ }
61+ eventQueue = [ ] ;
62+ }
63+ } )
64+ . catch ( function ( err ) {
65+ console . error (
66+ 'Error creating Rokt launcher:' ,
67+ err
68+ ) ;
69+ } ) ;
70+ } else {
71+ console . error (
72+ 'Rokt object is not available after script load.'
73+ ) ;
74+ }
75+ } ;
76+
77+ script . onerror = function ( error ) {
78+ console . error (
79+ 'Failed to load Rokt launcher script:' ,
80+ error
81+ ) ;
82+ } ;
1883
19- // var clientScript = document.createElement('script');
20- // clientScript.type = 'text/javascript';
21- // clientScript.async = true;
22- // clientScript.src = 'https://www.clientscript.com/static/clientSDK.js'; // <---- Update this to be your script
23- // (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(clientScript);
24- // clientScript.onload = function() {
25- // if (clientSDKObject && eventQueue.length > 0) {
26- // // Process any events that may have been queued up while forwarder was being initialized.
27- // for (var i = 0; i < eventQueue.length; i++) {
28- // processEvent(eventQueue[i]);
29- // }
30- // // now that each queued event is processed, we empty the eventQueue
31- // eventQueue = [];
32- // }
33- // clientSDKObject.initialize(forwarderSettings.apiKey);
34- // };
35- } else {
36- // For testing, you should fill out this section in order to ensure any required initialization calls are made,
37- // clientSDKObject.initialize(forwarderSettings.apiKey)
84+ target . appendChild ( script ) ;
85+ } else {
86+ // For testing, you can simulate initialization if needed.
87+ console . log (
88+ 'Test mode enabled – skipping Rokt launcher script load.'
89+ ) ;
90+ }
3891 }
39- }
92+ } ,
4093} ;
4194
42- module . exports = initialization ;
95+ module . exports = initialization ;
0 commit comments