feat: add use method for rokt kit#1067
Conversation
rmi22186
left a comment
There was a problem hiding this comment.
tiny comment for whitespace, otherwise LGTM!
|
@alexs-mparticle should review to understand what features we are adding as well |
@jaissica12 Not sure if @rmi22186 mentioned this, but we should also update DefinitelyTyped to reflect this new method as well. |
| try { | ||
| return this.kit.use<T>(name); | ||
| } catch (error) { | ||
| return Promise.reject(error instanceof Error ? error : new Error('Unknown error occurred')); |
There was a problem hiding this comment.
I think we should have a more explicit error message as we know that the use method is related to extensions.
| return Promise.reject(error instanceof Error ? error : new Error('Unknown error occurred')); | |
| return Promise.reject(error instanceof Error ? error : new Error('Error using extension: ' + name)); |
Thanks for mentioning, I'll create a ticket for this and raise PR with the changes |
|
We should also just add the remaining public methods to the snippet so that customers don't have to update them in the future. |
| export interface IRoktLauncher { | ||
| selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>; | ||
| hashAttributes: (attributes: IRoktPartnerAttributes) => Promise<Record<string, string>>; | ||
| use: <T = any>(name: string) => Promise<T>; |
There was a problem hiding this comment.
We should avoid using any.
| use: <T = any>(name: string) => Promise<T>; | |
| use: <T>(name: string) => Promise<T>; |
| setExtensionData<T>(extensionData: IRoktPartnerExtensionData<T>): void; | ||
| terminate: () => Promise<void>; | ||
| getVersion: () => Promise<string>; | ||
| use: <T = any>(name: string) => Promise<T>; |
There was a problem hiding this comment.
| use: <T = any>(name: string) => Promise<T>; | |
| use: <T>(name: string) => Promise<T>; |
| } | ||
| } | ||
|
|
||
| public use<T = any>(name: string): Promise<T> { |
There was a problem hiding this comment.
| public use<T = any>(name: string): Promise<T> { | |
| public use<T>(name: string): Promise<T> { |
|
|
||
| //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"); | ||
| (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","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"); |
There was a problem hiding this comment.
Bump the version number of the snippet.js and then run the build command again.
Co-authored-by: Robert Ing <rmi22186@gmail.com>
c624db9 to
27f7f18
Compare
| getVersion: () => Promise<string>; | ||
| terminate: () => Promise<void>; |
There was a problem hiding this comment.
I'd remove these for now
| getVersion: () => Promise<string>; | |
| terminate: () => Promise<void>; |
| terminate: () => Promise<void>; | ||
| getVersion: () => Promise<string>; |
There was a problem hiding this comment.
ditto
| terminate: () => Promise<void>; | |
| getVersion: () => Promise<string>; |
Add these to the branch you are creating for supporting these APIs so it all goes in as 1 PR.
| hashAttributes: jest.fn(), | ||
| selectPlacements: jest.fn() | ||
| selectPlacements: jest.fn(), | ||
| use: jest.fn(), |
There was a problem hiding this comment.
Can you create a test for use? Something like "should call kit.use with the same argument passed to mParticle.Rokt.use"
|
|
🎉 This PR is included in version 2.45.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |


Instructions
developmentSummary
usemethodroktManager.ts,snippet,snippet.rokt.jsand relates testsTesting Plan
Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)