Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ window.mParticle = {
};

//load the SDK
(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.5;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=["selectPlacements","hashAttributes","setExtensionData"];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");
</script>
(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.7;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=["selectPlacements","hashAttributes","setExtensionData","use","getVersion","terminate"];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 a,c,s=window.mParticle.config,l=s.isDevelopmentMode?1:0,w="?env="+l,d=window.mParticle.config.dataPlan;if(d){a=d.planId;c=d.planVersion;if(a){if(c&&(c<1||c>1e3)){c=null}w+="&plan_id="+a+(c?"&plan_version="+c:"")}}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");
```

You can then log events, for example, as follows:
Expand Down
5 changes: 4 additions & 1 deletion snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
window.mParticle.Rokt = {};
window.mParticle.config = window.mParticle.config || {};
window.mParticle.config.rq = [];
window.mParticle.config.snippetVersion = 2.5;
window.mParticle.config.snippetVersion = 2.7;
window.mParticle.ready = function(f) {
window.mParticle.config.rq.push(f);
};
Expand Down Expand Up @@ -49,6 +49,9 @@
'selectPlacements',
'hashAttributes',
'setExtensionData',
'use',
'getVersion',
'terminate',
];

// iterates through methods above to create stubs
Expand Down
2 changes: 1 addition & 1 deletion snippet.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion snippet.rokt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
window.mParticle.Rokt = {};
window.mParticle.config = window.mParticle.config || {};
window.mParticle.config.rq = [];
window.mParticle.config.snippetVersion = 2.6;
window.mParticle.config.snippetVersion = 2.7;
window.mParticle.ready = function(f) {
window.mParticle.config.rq.push(f);
};
Expand Down Expand Up @@ -49,6 +49,9 @@
'selectPlacements',
'hashAttributes',
'setExtensionData',
'use',
'getVersion',
'terminate',
];

// iterates through methods above to create stubs
Expand Down
2 changes: 1 addition & 1 deletion snippet.rokt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions src/roktManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export interface IRoktSelection {
export interface IRoktLauncher {
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
hashAttributes: (attributes: IRoktPartnerAttributes) => Promise<Record<string, string>>;
use: <T>(name: string) => Promise<T>;
getVersion: () => Promise<string>;
terminate: () => Promise<void>;
}

export interface IRoktMessage {
Expand All @@ -62,6 +65,9 @@ export interface IRoktKit {
hashAttributes: (attributes: IRoktPartnerAttributes) => Promise<Record<string, string>>;
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
setExtensionData<T>(extensionData: IRoktPartnerExtensionData<T>): void;
terminate: () => Promise<void>;
getVersion: () => Promise<string>;
use: <T>(name: string) => Promise<T>;
launcherOptions?: Dictionary<any>;
}

Expand Down Expand Up @@ -251,6 +257,42 @@ export default class RoktManager {
}
}

public use<T>(name: string): Promise<T> {
if (!this.isReady()) {
return this.deferredCall<T>('use', name);
}

try {
return this.kit.use<T>(name);
} catch (error) {
return Promise.reject(error instanceof Error ? error : new Error('Error using extension: ' + name));
}
}

public terminate(): Promise<void> {
if (!this.isReady()) {
return this.deferredCall<void>('terminate', {});
}

try {
return this.kit.terminate();
} catch (error) {
return Promise.reject(error instanceof Error ? error : new Error('Error terminating'));
}
}

public getVersion(): Promise<string> {
if (!this.isReady()) {
return this.deferredCall<string>('getVersion', {});
}

try {
return this.kit.getVersion();
} catch (error) {
return Promise.reject(error instanceof Error ? error : new Error('Error getting the version'));
}
}

public getLocalSessionAttributes(): LocalSessionAttributes {
return this.store.getLocalSessionAttributes();
}
Expand Down
Loading
Loading