Skip to content

Commit 49202b3

Browse files
fix: Add Rokt Wrapper Methods to snippet.js (#997)
1 parent d96c926 commit 49202b3

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ window.mParticle = {
4646
};
4747

4848
//load the SDK
49-
(
50-
function(t){window.mParticle=window.mParticle||{};window.mParticle.EventType={Unknown:0,Navigation:1,Location:2,Search:3,Transaction:4,UserContent:5,UserPreference:6,Social:7,Other:8};window.mParticle.eCommerce={Cart:{}};window.mParticle.Identity={};window.mParticle.config=window.mParticle.config||{};window.mParticle.config.rq=[];window.mParticle.config.snippetVersion=2.3;window.mParticle.ready=function(t){window.mParticle.config.rq.push(t)};var e=["endSession","logError","logBaseEvent","logEvent","logForm","logLink","logPageView","setSessionAttribute","setAppName","setAppVersion","setOptOut","setPosition","startNewSession","startTrackingLocation","stopTrackingLocation"];var o=["setCurrencyCode","logCheckout"];var i=["identify","login","logout","modify"];e.forEach(function(t){window.mParticle[t]=n(t)});o.forEach(function(t){window.mParticle.eCommerce[t]=n(t,"eCommerce")});i.forEach(function(t){window.mParticle.Identity[t]=n(t,"Identity")});function n(e,o){return function(){if(o){e=o+"."+e}var t=Array.prototype.slice.call(arguments);t.unshift(e);window.mParticle.config.rq.push(t)}}var dpId,dpV,config=window.mParticle.config,env=config.isDevelopmentMode?1:0,dbUrl="?env="+env,dataPlan=window.mParticle.config.dataPlan;dataPlan&&(dpId=dataPlan.planId,dpV=dataPlan.planVersion,dpId&&(dpV&&(dpV<1||dpV>1e3)&&(dpV=null),dbUrl+="&plan_id="+dpId+(dpV?"&plan_version="+dpV:"")));var mp=document.createElement("script");mp.type="text/javascript";mp.async=true;mp.src=("https:"==document.location.protocol?"https://jssdkcdns":"http://jssdkcdn")+".mparticle.com/js/v2/"+t+"/mparticle.js" + dbUrl;var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(mp,c)}
51-
)("REPLACE WITH API KEY");
49+
(function(e){window.mParticle=window.mParticle||{};window.mParticle.EventType={Unknown:0,Navigation:1,Location:2,Search:3,Transaction:4,UserContent:5,UserPreference:6,Social:7,Other:8,Media:9};window.mParticle.eCommerce={Cart:{}};window.mParticle.Identity={};window.mParticle.Rokt={};window.mParticle.config=window.mParticle.config||{};window.mParticle.config.rq=[];window.mParticle.config.snippetVersion=2.4;window.mParticle.ready=function(e){window.mParticle.config.rq.push(e)};var t=["endSession","logError","logBaseEvent","logEvent","logForm","logLink","logPageView","setSessionAttribute","setAppName","setAppVersion","setOptOut","setPosition","startNewSession","startTrackingLocation","stopTrackingLocation"];var i=["setCurrencyCode","logCheckout"];var n=["identify","login","logout","modify"];var o=["attachLauncher","selectPlacements"];t.forEach(function(e){window.mParticle[e]=r(e)});i.forEach(function(e){window.mParticle.eCommerce[e]=r(e,"eCommerce")});n.forEach(function(e){window.mParticle.Identity[e]=r(e,"Identity")});o.forEach(function(e){window.mParticle.Rokt[e]=r(e,"Rokt")});function r(t,i){return function(){if(i){t=i+"."+t}var e=Array.prototype.slice.call(arguments);e.unshift(t);window.mParticle.config.rq.push(e)}}var c,a,s=window.mParticle.config,l=s.isDevelopmentMode?1:0,w="?env="+l,d=window.mParticle.config.dataPlan;if(d){c=d.planId;a=d.planVersion;if(c){if(a&&(a<1||a>1e3)){a=null}w+="&plan_id="+c+(a?"&plan_version="+a:"")}}var m=window.mParticle.config.versions;var f=[];if(m){Object.keys(m).forEach(function(e){f.push(e+"="+m[e])})}var p=document.createElement("script");p.type="text/javascript";p.async=true;p.src=("https:"==document.location.protocol?"https://jssdkcdns":"http://jssdkcdn")+".mparticle.com/js/v2/"+e+"/mparticle.js"+w+"&"+f.join("&");var P=document.getElementsByTagName("script")[0];P.parentNode.insertBefore(p,P)})("REPLACE WITH API KEY");
5250
</script>
5351
```
5452

snippet.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
UserPreference: 6,
1313
Social: 7,
1414
Other: 8,
15+
Media: 9,
1516
};
1617
window.mParticle.eCommerce = { Cart: {} };
1718
window.mParticle.Identity = {};
19+
window.mParticle.Rokt = {};
1820
window.mParticle.config = window.mParticle.config || {};
1921
window.mParticle.config.rq = [];
20-
window.mParticle.config.snippetVersion = 2.3;
22+
window.mParticle.config.snippetVersion = 2.4;
2123
window.mParticle.ready = function(f) {
2224
window.mParticle.config.rq.push(f);
2325
};
@@ -43,6 +45,7 @@
4345
];
4446
var ecommerceMethods = ['setCurrencyCode', 'logCheckout'];
4547
var identityMethods = ['identify', 'login', 'logout', 'modify'];
48+
var roktMethods = ['attachLauncher', 'selectPlacements'];
4649

4750
// iterates through methods above to create stubs
4851
mainMethods.forEach(function(method) {
@@ -54,6 +57,9 @@
5457
identityMethods.forEach(function(method) {
5558
window.mParticle.Identity[method] = preloadMethod(method, 'Identity');
5659
});
60+
roktMethods.forEach(function(method) {
61+
window.mParticle.Rokt[method] = preloadMethod(method, 'Rokt');
62+
});
5763

5864
// stubbing function
5965
// pushes an array of 2 arguments into readyQueue: 1. the method, and 2. the arguments passed to the method

snippet.min.js

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snippet/tests-snippet.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('snippet', function() {
121121
});
122122

123123
it('mParticle object should have EventTypes on it', function(done) {
124-
Object.keys(mParticle.EventType).length.should.equal(9);
124+
Object.keys(mParticle.EventType).length.should.equal(10);
125125
mParticle.EventType.Unknown.should.equal(0);
126126
mParticle.EventType.Navigation.should.equal(1);
127127
mParticle.EventType.Location.should.equal(2);
@@ -131,7 +131,16 @@ describe('snippet', function() {
131131
mParticle.EventType.UserPreference.should.equal(6);
132132
mParticle.EventType.Social.should.equal(7);
133133
mParticle.EventType.Other.should.equal(8);
134+
mParticle.EventType.Media.should.equal(9);
134135

135136
done();
136137
});
138+
139+
it('mParticle object should proxy Rokt methods', function(done) {
140+
mParticle.Rokt.attachLauncher();
141+
mParticle.Rokt.selectPlacements();
142+
mParticle.config.rq[0][0].should.equal('Rokt.attachLauncher');
143+
mParticle.config.rq[1][0].should.equal('Rokt.selectPlacements');
144+
done();
145+
});
137146
});

0 commit comments

Comments
 (0)