Skip to content

feat: add use method for rokt kit#1067

Merged
jaissica12 merged 7 commits into
developmentfrom
feat/SDKE-143-support-mParticle.Rokt.use-in-mp-web-sdk
Sep 15, 2025
Merged

feat: add use method for rokt kit#1067
jaissica12 merged 7 commits into
developmentfrom
feat/SDKE-143-support-mParticle.Rokt.use-in-mp-web-sdk

Conversation

@jaissica12

Copy link
Copy Markdown
Contributor

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

  • Added use method roktManager.ts, snippet, snippet.rokt.js and relates tests

Testing Plan

  • Was this tested locally? If not, explain why.
  • {explain how this has been tested, and what, if any, additional testing should be done}

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

@jaissica12 jaissica12 requested a review from rmi22186 September 9, 2025 20:38
@jaissica12 jaissica12 marked this pull request as ready for review September 9, 2025 20:43

@rmi22186 rmi22186 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny comment for whitespace, otherwise LGTM!

Comment thread test/jest/roktManager.spec.ts Outdated
@rmi22186

Copy link
Copy Markdown
Member

@alexs-mparticle should review to understand what features we are adding as well

@alexs-mparticle

Copy link
Copy Markdown
Collaborator

@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.

Comment thread src/roktManager.ts Outdated
try {
return this.kit.use<T>(name);
} catch (error) {
return Promise.reject(error instanceof Error ? error : new Error('Unknown error occurred'));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a more explicit error message as we know that the use method is related to extensions.

Suggested change
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));

@jaissica12

Copy link
Copy Markdown
Contributor Author

@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.

Thanks for mentioning, I'll create a ticket for this and raise PR with the changes

@rmi22186

Copy link
Copy Markdown
Member

We should also just add the remaining public methods to the snippet so that customers don't have to update them in the future.

@jaissica12 jaissica12 changed the title feat: added use method for rokt kit feat: added use, getVersion, terminate method for rokt kit Sep 12, 2025
Comment thread src/roktManager.ts Outdated
export interface IRoktLauncher {
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
hashAttributes: (attributes: IRoktPartnerAttributes) => Promise<Record<string, string>>;
use: <T = any>(name: string) => Promise<T>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using any.

Suggested change
use: <T = any>(name: string) => Promise<T>;
use: <T>(name: string) => Promise<T>;

Comment thread src/roktManager.ts Outdated
setExtensionData<T>(extensionData: IRoktPartnerExtensionData<T>): void;
terminate: () => Promise<void>;
getVersion: () => Promise<string>;
use: <T = any>(name: string) => Promise<T>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use: <T = any>(name: string) => Promise<T>;
use: <T>(name: string) => Promise<T>;

Comment thread src/roktManager.ts Outdated
}
}

public use<T = any>(name: string): Promise<T> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public use<T = any>(name: string): Promise<T> {
public use<T>(name: string): Promise<T> {

Comment thread snippet.js
Comment thread README.md Outdated

//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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump the version number of the snippet.js and then run the build command again.

@jaissica12 jaissica12 changed the title feat: added use, getVersion, terminate method for rokt kit feat: add use method for rokt kit Sep 15, 2025
@jaissica12 jaissica12 force-pushed the feat/SDKE-143-support-mParticle.Rokt.use-in-mp-web-sdk branch from c624db9 to 27f7f18 Compare September 15, 2025 14:55
Comment thread src/roktManager.ts Outdated
Comment on lines +42 to +43
getVersion: () => Promise<string>;
terminate: () => Promise<void>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove these for now

Suggested change
getVersion: () => Promise<string>;
terminate: () => Promise<void>;

Comment thread src/roktManager.ts Outdated
Comment on lines +68 to +69
terminate: () => Promise<void>;
getVersion: () => Promise<string>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Suggested change
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(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a test for use? Something like "should call kit.use with the same argument passed to mParticle.Rokt.use"

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
10.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@jaissica12 jaissica12 merged commit bdcd4c5 into development Sep 15, 2025
42 of 49 checks passed
github-actions Bot pushed a commit that referenced this pull request Sep 15, 2025
# [2.45.0](v2.44.0...v2.45.0) (2025-09-15)

### Features

* add use method for rokt kit ([#1067](#1067)) ([bdcd4c5](bdcd4c5))
* added noFunctional and noTargeting flags ([#1059](#1059)) ([9235483](9235483))
@mparticle-automation

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 2.45.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants