Skip to content

Commit 92f16f5

Browse files
crisryantanalexs-mparticle
authored andcommitted
feat: implement rokt launcher into initForwarder (#2)
1 parent dabce4b commit 92f16f5

File tree

16 files changed

+14662
-13307
lines changed

16 files changed

+14662
-13307
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"no-prototype-builtins": "off",
2525
"no-empty": "off",
2626
"no-useless-escape": "off",
27-
"no-unexpected-multiline": "off"
27+
"no-unexpected-multiline": "off",
28+
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
2829
}
29-
}
30+
}

dist/.keep

Whitespace-only changes.

package-lock.json

Lines changed: 14384 additions & 13087 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
{
2-
"name": "@mparticle/web-rokt-wsdk-kit",
3-
"version": "1.0.0",
4-
"main": "dist/RoktWSDK-Kit.common.js",
5-
"files": [
6-
"dist/RoktWSDK-Kit.common.js"
7-
],
8-
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-rokt",
9-
"scripts": {
10-
"build": "ENVIRONMENT=production rollup --config rollup.config.js",
11-
"build:test": "rollup --config rollup.test.config.js",
12-
"lint": "eslint src/ test/src/",
13-
"lint:fix": "eslint src/ test/src/ --fix",
14-
"watch": "ENVIRONMENT=production rollup --config rollup.config.js -w",
15-
"test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
16-
"test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js",
17-
"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"
18-
},
19-
"publishConfig": {
20-
"access": "public"
21-
},
22-
"devDependencies": {
23-
"@mparticle/web-kit-wrapper": "^1.0.5",
24-
"@semantic-release/changelog": "^5.0.1",
25-
"@semantic-release/exec": "^5.0.0",
26-
"@semantic-release/git": "^9.0.0",
27-
"mocha": "^5.2.0",
28-
"chai": "^4.2.0",
29-
"eslint": "^7.25.0",
30-
"eslint-config-prettier": "8.3.0",
31-
"eslint-plugin-prettier": "3.4.1",
32-
"karma": "^5.1.0",
33-
"karma-chai": "^0.1.0",
34-
"karma-chrome-launcher": "^3.1.0",
35-
"karma-firefox-launcher": "^2.1.0",
36-
"karma-mocha": "^2.0.1",
37-
"prettier": "^2.4.1",
38-
"rollup": "^1.15.6",
39-
"rollup-plugin-commonjs": "^10.0.0",
40-
"rollup-plugin-node-resolve": "^5.0.3",
41-
"shelljs": "0.8.3",
42-
"should": "13.2.3",
43-
"watchify": "^3.11.0"
44-
},
45-
"dependencies": {
46-
"@mparticle/web-sdk": "^2.20.0"
47-
},
48-
"license": "Apache-2.0"
49-
}
2+
"name": "@mparticle/web-rokt-wsdk-kit",
3+
"version": "0.0.1",
4+
"main": "dist/RoktWsdk-Kit.common.js",
5+
"files": [
6+
"dist/RoktWsdk-Kit.common.js"
7+
],
8+
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-rokt",
9+
"scripts": {
10+
"build": "ENVIRONMENT=production rollup --config rollup.config.js",
11+
"build:test": "rollup --config rollup.test.config.js",
12+
"lint": "eslint src/ test/src/",
13+
"lint:fix": "eslint src/ test/src/ --fix",
14+
"watch": "ENVIRONMENT=production rollup --config rollup.config.js -w",
15+
"test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
16+
"test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js",
17+
"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"
18+
},
19+
"publishConfig": {
20+
"access": "public"
21+
},
22+
"devDependencies": {
23+
"@mparticle/web-kit-wrapper": "^1.0.5",
24+
"@semantic-release/changelog": "^5.0.1",
25+
"@semantic-release/exec": "^5.0.0",
26+
"@semantic-release/git": "^9.0.0",
27+
"mocha": "^5.2.0",
28+
"chai": "^4.2.0",
29+
"eslint": "^7.25.0",
30+
"eslint-config-prettier": "8.3.0",
31+
"eslint-plugin-prettier": "3.4.1",
32+
"karma": "^5.1.0",
33+
"karma-chai": "^0.1.0",
34+
"karma-chrome-launcher": "^3.1.0",
35+
"karma-firefox-launcher": "^2.1.0",
36+
"karma-mocha": "^2.0.1",
37+
"prettier": "^2.4.1",
38+
"rollup": "^1.15.6",
39+
"rollup-plugin-commonjs": "^10.0.0",
40+
"rollup-plugin-node-resolve": "^5.0.3",
41+
"shelljs": "0.8.3",
42+
"should": "13.2.3",
43+
"watchify": "^3.11.0"
44+
},
45+
"dependencies": {
46+
"@mparticle/web-sdk": "^2.20.0"
47+
},
48+
"license": "Apache-2.0"
49+
}

release.config.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,45 @@ module.exports = {
1818
{ type: 'style', release: 'patch' },
1919
{ type: 'build', release: 'patch' },
2020
{ type: 'chore', release: 'patch' },
21-
{ type: 'revert', release: 'patch' }
22-
]
23-
}
21+
{ type: 'revert', release: 'patch' },
22+
],
23+
},
2424
],
2525
[
2626
'@semantic-release/release-notes-generator',
2727
{
28-
preset: 'angular'
29-
}
28+
preset: 'angular',
29+
},
3030
],
3131
[
3232
'@semantic-release/changelog',
3333
{
34-
changelogFile: 'CHANGELOG.md'
35-
}
34+
changelogFile: 'CHANGELOG.md',
35+
},
3636
],
3737
['@semantic-release/npm'],
3838
[
3939
'@semantic-release/exec',
4040
{
41-
prepareCmd: 'sh ./scripts/release.sh'
42-
}
41+
prepareCmd: 'sh ./scripts/release.sh',
42+
},
4343
],
4444
[
4545
'@semantic-release/github',
4646
{
47-
assets: ['dist/RoktWSDK-Kit.common.js', 'dist/RoktWSDK-Kit.iife.js']
48-
}
47+
assets: [
48+
'dist/RoktWsdk-Kit.common.js',
49+
'dist/RoktWsdk-Kit.iife.js',
50+
],
51+
},
4952
],
5053
[
5154
'@semantic-release/git',
5255
{
5356
assets: ['package.json', 'package-lock.json', 'CHANGELOG.md'],
5457
message:
55-
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
56-
}
57-
]
58-
]
58+
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
59+
},
60+
],
61+
],
5962
};

src/commerce-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function CommerceHandler(common) {
22
this.common = common || {};
33
}
44

5-
CommerceHandler.prototype.logCommerceEvent = function() {
5+
CommerceHandler.prototype.logCommerceEvent = function () {
66
/*
77
Sample ecommerce event schema:
88
{

src/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ function Common() {}
22

33
Common.prototype.exampleMethod = function () {
44
return 'I am an example';
5-
}
5+
};
66

7-
module.exports = Common;
7+
module.exports = Common;

src/event-handler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ A non-ecommerce event has the following schema:
1616
function EventHandler(common) {
1717
this.common = common || {};
1818
}
19-
EventHandler.prototype.logEvent = function(event) {};
20-
EventHandler.prototype.logError = function(event) {
19+
EventHandler.prototype.logEvent = function (_event) {};
20+
EventHandler.prototype.logError = function (_event) {
2121
// The schema for a logError event is the same, but noteworthy differences are as follows:
2222
// {
2323
// EventAttributes: {m: 'name of error passed into MP', s: "Error", t: 'stack trace in string form if applicable'},
2424
// EventName: "Error"
2525
// }
2626
};
27-
EventHandler.prototype.logPageView = function(event) {
27+
EventHandler.prototype.logPageView = function (_event) {
2828
/* The schema for a logPagView event is the same, but noteworthy differences are as follows:
2929
{
3030
EventAttributes: {hostname: "www.google.com", title: 'Test Page'}, // These are event attributes only if no additional event attributes are explicitly provided to mParticle.logPageView(...)
3131
}
3232
*/
3333
};
3434

35-
module.exports = EventHandler;
35+
module.exports = EventHandler;

src/identity-handler.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ For more userIdentity types, see https://docs.mparticle.com/developers/sdk/web/i
2121
function IdentityHandler(common) {
2222
this.common = common || {};
2323
}
24-
IdentityHandler.prototype.onUserIdentified = function(mParticleUser) {};
25-
IdentityHandler.prototype.onIdentifyComplete = function(
26-
mParticleUser,
27-
identityApiRequest
24+
IdentityHandler.prototype.onUserIdentified = function (_mParticleUser) {};
25+
IdentityHandler.prototype.onIdentifyComplete = function (
26+
_mParticleUser,
27+
_identityApiRequest
2828
) {};
29-
IdentityHandler.prototype.onLoginComplete = function(
30-
mParticleUser,
31-
identityApiRequest
29+
IdentityHandler.prototype.onLoginComplete = function (
30+
_mParticleUser,
31+
_identityApiRequest
3232
) {};
33-
IdentityHandler.prototype.onLogoutComplete = function(
34-
mParticleUser,
35-
identityApiRequest
33+
IdentityHandler.prototype.onLogoutComplete = function (
34+
_mParticleUser,
35+
_identityApiRequest
3636
) {};
37-
IdentityHandler.prototype.onModifyComplete = function(
38-
mParticleUser,
39-
identityApiRequest
37+
IdentityHandler.prototype.onModifyComplete = function (
38+
_mParticleUser,
39+
_identityApiRequest
4040
) {};
4141

4242
/* In previous versions of the mParticle web SDK, setting user identities on
4343
kits is only reachable via the onSetUserIdentity method below. We recommend
4444
filling out `onSetUserIdentity` for maximum compatibility
4545
*/
46-
IdentityHandler.prototype.onSetUserIdentity = function(
47-
forwarderSettings,
48-
id,
49-
type
46+
IdentityHandler.prototype.onSetUserIdentity = function (
47+
_forwarderSettings,
48+
_id,
49+
_type
5050
) {};
5151

52-
module.exports = IdentityHandler;
52+
module.exports = IdentityHandler;

src/initialization.js

Lines changed: 82 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,95 @@
1+
var roktLauncherScript = 'https://apps.rokt.com/wsdk/integrations/launcher.js';
2+
13
var 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

Comments
 (0)