-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement rokt launcher into initForwarder #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexs-mparticle
merged 15 commits into
development
from
feat/implement-rokt-mparticle-poc
Mar 7, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
746db89
feat: implement rokt launcher into initForwarder
crisryantan 897b60a
Merge branch 'development' into feat/implement-rokt-mparticle-poc
crisryantan 6a9b918
feat: update implementation in creating launcher
crisryantan ce891a0
feat: add lint command to fix build
crisryantan c6fda9d
fix: run lint script and fix errors
crisryantan 766531c
fix: resolve conflict on .nvmrc
crisryantan 476222f
feat: add moduleId
crisryantan 7754185
refactor: implement suggested changes
crisryantan 6573575
fix: additional cleanup
crisryantan 4c3dcb9
fix: typo on filename
crisryantan 67ff9ff
fix: update references to match accurately generated filename
crisryantan daad169
fix: typo
crisryantan 71ad7eb
Refactor sandbox mode initialization logic
crisryantan 94261cf
fix: lint fix
crisryantan e93e79b
Update src/initialization.js
crisryantan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,49 @@ | ||
| { | ||
| "name": "@mparticle/web-rokt-wsdk-kit", | ||
| "version": "1.0.0", | ||
| "main": "dist/RoktWSDK-Kit.common.js", | ||
| "files": [ | ||
| "dist/RoktWSDK-Kit.common.js" | ||
| ], | ||
| "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-rokt", | ||
| "scripts": { | ||
| "build": "ENVIRONMENT=production rollup --config rollup.config.js", | ||
| "build:test": "rollup --config rollup.test.config.js", | ||
| "lint": "eslint src/ test/src/", | ||
| "lint:fix": "eslint src/ test/src/ --fix", | ||
| "watch": "ENVIRONMENT=production rollup --config rollup.config.js -w", | ||
| "test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js", | ||
| "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js", | ||
| "testEndToEnd": "ENVIRONMENT=testEndToEnd rollup --config rollup.config.js && open http://localhost:8082/node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/index.html && node node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/server" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "devDependencies": { | ||
| "@mparticle/web-kit-wrapper": "^1.0.5", | ||
| "@semantic-release/changelog": "^5.0.1", | ||
| "@semantic-release/exec": "^5.0.0", | ||
| "@semantic-release/git": "^9.0.0", | ||
| "mocha": "^5.2.0", | ||
| "chai": "^4.2.0", | ||
| "eslint": "^7.25.0", | ||
| "eslint-config-prettier": "8.3.0", | ||
| "eslint-plugin-prettier": "3.4.1", | ||
| "karma": "^5.1.0", | ||
| "karma-chai": "^0.1.0", | ||
| "karma-chrome-launcher": "^3.1.0", | ||
| "karma-firefox-launcher": "^2.1.0", | ||
| "karma-mocha": "^2.0.1", | ||
| "prettier": "^2.4.1", | ||
| "rollup": "^1.15.6", | ||
| "rollup-plugin-commonjs": "^10.0.0", | ||
| "rollup-plugin-node-resolve": "^5.0.3", | ||
| "shelljs": "0.8.3", | ||
| "should": "13.2.3", | ||
| "watchify": "^3.11.0" | ||
| }, | ||
| "dependencies": { | ||
| "@mparticle/web-sdk": "^2.20.0" | ||
| }, | ||
| "license": "Apache-2.0" | ||
| } | ||
| "name": "@mparticle/web-rokt-wsdk-kit", | ||
| "version": "0.0.1", | ||
| "main": "dist/RoktWsdk-Kit.common.js", | ||
| "files": [ | ||
| "dist/RoktWsdk-Kit.common.js" | ||
| ], | ||
| "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-rokt", | ||
| "scripts": { | ||
| "build": "ENVIRONMENT=production rollup --config rollup.config.js", | ||
| "build:test": "rollup --config rollup.test.config.js", | ||
| "lint": "eslint src/ test/src/", | ||
| "lint:fix": "eslint src/ test/src/ --fix", | ||
| "watch": "ENVIRONMENT=production rollup --config rollup.config.js -w", | ||
| "test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js", | ||
| "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js", | ||
| "testEndToEnd": "ENVIRONMENT=testEndToEnd rollup --config rollup.config.js && open http://localhost:8082/node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/index.html && node node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/server" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "devDependencies": { | ||
| "@mparticle/web-kit-wrapper": "^1.0.5", | ||
| "@semantic-release/changelog": "^5.0.1", | ||
| "@semantic-release/exec": "^5.0.0", | ||
| "@semantic-release/git": "^9.0.0", | ||
| "mocha": "^5.2.0", | ||
| "chai": "^4.2.0", | ||
| "eslint": "^7.25.0", | ||
| "eslint-config-prettier": "8.3.0", | ||
| "eslint-plugin-prettier": "3.4.1", | ||
| "karma": "^5.1.0", | ||
| "karma-chai": "^0.1.0", | ||
| "karma-chrome-launcher": "^3.1.0", | ||
| "karma-firefox-launcher": "^2.1.0", | ||
| "karma-mocha": "^2.0.1", | ||
| "prettier": "^2.4.1", | ||
| "rollup": "^1.15.6", | ||
| "rollup-plugin-commonjs": "^10.0.0", | ||
| "rollup-plugin-node-resolve": "^5.0.3", | ||
| "shelljs": "0.8.3", | ||
| "should": "13.2.3", | ||
| "watchify": "^3.11.0" | ||
| }, | ||
| "dependencies": { | ||
| "@mparticle/web-sdk": "^2.20.0" | ||
| }, | ||
| "license": "Apache-2.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,42 +1,95 @@ | ||||||||||||||||||||||
| var roktLauncherScript = 'https://apps.rokt.com/wsdk/integrations/launcher.js'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var initialization = { | ||||||||||||||||||||||
| name: 'insertSDKNameHere', | ||||||||||||||||||||||
| /* ****** Fill out initForwarder to load your SDK ****** | ||||||||||||||||||||||
| 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) { | ||||||||||||||||||||||
| /* `forwarderSettings` contains your SDK specific settings such as apiKey that your customer needs in order to initialize your SDK properly */ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| initForwarder: function ( | ||||||||||||||||||||||
| forwarderSettings, | ||||||||||||||||||||||
| testMode, | ||||||||||||||||||||||
| _userAttributes, | ||||||||||||||||||||||
| _userIdentities, | ||||||||||||||||||||||
| processEvent, | ||||||||||||||||||||||
| eventQueue, | ||||||||||||||||||||||
| _isInitialized, | ||||||||||||||||||||||
| _common, | ||||||||||||||||||||||
| _appVersion, | ||||||||||||||||||||||
| _appName, | ||||||||||||||||||||||
| _customFlags, | ||||||||||||||||||||||
| _clientId | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
| if (!testMode) { | ||||||||||||||||||||||
| /* Load your Web SDK here using a variant of your snippet from your readme that your customers would generally put into their <head> tags | ||||||||||||||||||||||
| Generally, our integrations create script tags and append them to the <head>. Please follow the following format as a guide: | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| 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 = []; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+53
to
+62
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a use case for an mparticle event to be passed to the Rokt SDK for processing? I don't think so. It doesn't hurt to have this, but if Rokt never processes mParticle events, then this can be removed.
Suggested change
|
||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| .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 | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // var clientScript = document.createElement('script'); | ||||||||||||||||||||||
| // clientScript.type = 'text/javascript'; | ||||||||||||||||||||||
| // clientScript.async = true; | ||||||||||||||||||||||
| // clientScript.src = 'https://www.clientscript.com/static/clientSDK.js'; // <---- Update this to be your script | ||||||||||||||||||||||
| // (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(clientScript); | ||||||||||||||||||||||
| // clientScript.onload = function() { | ||||||||||||||||||||||
| // if (clientSDKObject && eventQueue.length > 0) { | ||||||||||||||||||||||
| // // Process any events that may have been queued up while forwarder was being initialized. | ||||||||||||||||||||||
| // for (var i = 0; i < eventQueue.length; i++) { | ||||||||||||||||||||||
| // processEvent(eventQueue[i]); | ||||||||||||||||||||||
| // } | ||||||||||||||||||||||
| // // now that each queued event is processed, we empty the eventQueue | ||||||||||||||||||||||
| // eventQueue = []; | ||||||||||||||||||||||
| // } | ||||||||||||||||||||||
| // clientSDKObject.initialize(forwarderSettings.apiKey); | ||||||||||||||||||||||
| // }; | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| // For testing, you should fill out this section in order to ensure any required initialization calls are made, | ||||||||||||||||||||||
| // clientSDKObject.initialize(forwarderSettings.apiKey) | ||||||||||||||||||||||
| 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; | ||||||||||||||||||||||
| module.exports = initialization; | ||||||||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.