Skip to content

Commit a2883ea

Browse files
Merge branch 'development' into fix/SDKE-846-identity-select-placements
2 parents ac52bd9 + 085ab44 commit a2883ea

4 files changed

Lines changed: 75 additions & 5 deletions

File tree

src/mp-instance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,8 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
14381438
mpInstance.Identity,
14391439
mpInstance._Store,
14401440
mpInstance.Logger,
1441-
roktOptions
1441+
roktOptions,
1442+
mpInstance.captureTiming
14421443
);
14431444
}
14441445

src/roktManager.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { SDKIdentityApi } from "./identity.interfaces";
1414
import { SDKLoggerApi } from "./sdkRuntimeModels";
1515
import { IStore, LocalSessionAttributes } from "./store";
1616
import { UserIdentities } from "@mparticle/web-sdk";
17-
import { IdentityType } from "./types";
17+
import { IdentityType, PerformanceMarkType } from "./types";
1818

1919
// https://docs.rokt.com/developers/integration-guides/web/library/attributes
2020
export type RoktAttributeValueArray = Array<string | number | boolean>;
@@ -101,7 +101,7 @@ export default class RoktManager {
101101
private logger: SDKLoggerApi;
102102
private domain?: string;
103103
private mappedEmailShaIdentityType?: string | null;
104-
104+
private captureTiming?: (metricsName: string) => void;
105105
/**
106106
* Initializes the RoktManager with configuration settings and user data.
107107
*
@@ -110,6 +110,7 @@ export default class RoktManager {
110110
* @param {SDKIdentityApi} identityService - The mParticle Identity instance
111111
* @param {SDKLoggerApi} logger - The mParticle Logger instance
112112
* @param {IRoktOptions} options - Options for the RoktManager
113+
* @param {Function} captureTiming - Function to capture performance timing marks
113114
*
114115
* @throws Logs error to console if placementAttributesMapping parsing fails
115116
*/
@@ -119,7 +120,8 @@ export default class RoktManager {
119120
identityService: SDKIdentityApi,
120121
store: IStore,
121122
logger?: SDKLoggerApi,
122-
options?: IRoktOptions
123+
options?: IRoktOptions,
124+
captureTiming?: (metricsName: string) => void
123125
): void {
124126
const { userAttributeFilters, settings } = roktConfig || {};
125127
const { placementAttributesMapping, hashedEmailUserIdentityType } = settings || {};
@@ -128,6 +130,7 @@ export default class RoktManager {
128130
this.identityService = identityService;
129131
this.store = store;
130132
this.logger = logger;
133+
this.captureTiming = captureTiming;
131134

132135
this.filters = {
133136
userAttributeFilters,
@@ -177,6 +180,10 @@ export default class RoktManager {
177180
* });
178181
*/
179182
public async selectPlacements(options: IRoktSelectPlacementsOptions): Promise<IRoktSelection> {
183+
if (this.captureTiming) {
184+
this.captureTiming(PerformanceMarkType.JointSdkSelectPlacements);
185+
}
186+
180187
// Queue if kit isn't ready OR if identity is in flight
181188
if (!this.isReady() || this.store?.identityCallInFlight) {
182189
return this.deferredCall<IRoktSelection>('selectPlacements', options);
@@ -556,4 +563,4 @@ export default class RoktManager {
556563

557564
return false; // Values are the same
558565
}
559-
}
566+
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ export const ApplicationTransitionType = {
393393

394394
export const PerformanceMarkType = {
395395
SdkStart: 'mp:sdkStart' as const,
396+
JointSdkSelectPlacements: 'mp:jointSdkSelectPlacements' as const,
396397
}
397398

398399
export default {

test/jest/roktManager.spec.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IMParticleWebSDKInstance } from "../../src/mp-instance";
55
import RoktManager, { IRoktKit, IRoktSelectPlacementsOptions } from "../../src/roktManager";
66
import { IStore } from "../../src/store";
77
import { testMPID } from '../src/config/constants';
8+
import { PerformanceMarkType } from "../../src/types";
89

910
const resolvePromise = () => new Promise(resolve => setTimeout(resolve, 0));
1011

@@ -802,6 +803,66 @@ describe('RoktManager', () => {
802803
jest.clearAllMocks();
803804
});
804805

806+
it('should capture jointSdkSelectPlacements timing when selectPlacements is called', () => {
807+
const mockCaptureTiming = jest.fn();
808+
roktManager.init(
809+
{} as IKitConfigs,
810+
{} as IMParticleUser,
811+
mockMPInstance.Identity,
812+
mockMPInstance._Store,
813+
mockMPInstance.Logger,
814+
undefined,
815+
mockCaptureTiming
816+
);
817+
818+
const kit: IRoktKit = {
819+
launcher: {
820+
selectPlacements: jest.fn(),
821+
hashAttributes: jest.fn(),
822+
use: jest.fn(),
823+
},
824+
filters: undefined,
825+
filteredUser: undefined,
826+
userAttributes: undefined,
827+
selectPlacements: jest.fn(),
828+
hashAttributes: jest.fn(),
829+
setExtensionData: jest.fn(),
830+
use: jest.fn(),
831+
};
832+
833+
roktManager.attachKit(kit);
834+
835+
const options = {
836+
attributes: {}
837+
} as IRoktSelectPlacementsOptions;
838+
839+
roktManager.selectPlacements(options);
840+
expect(mockCaptureTiming).toHaveBeenCalledWith(PerformanceMarkType.JointSdkSelectPlacements);
841+
expect(mockCaptureTiming).toHaveBeenCalledTimes(1);
842+
});
843+
844+
it('should capture jointSdkSelectPlacements timing even when kit is not ready (deferred call)', () => {
845+
const mockCaptureTiming = jest.fn();
846+
roktManager.init(
847+
{} as IKitConfigs,
848+
{} as IMParticleUser,
849+
mockMPInstance.Identity,
850+
mockMPInstance._Store,
851+
mockMPInstance.Logger,
852+
undefined,
853+
mockCaptureTiming
854+
);
855+
856+
const options = {
857+
attributes: {}
858+
} as IRoktSelectPlacementsOptions;
859+
860+
roktManager.selectPlacements(options);
861+
expect(mockCaptureTiming).toHaveBeenCalledWith(PerformanceMarkType.JointSdkSelectPlacements);
862+
expect(mockCaptureTiming).toHaveBeenCalledTimes(1);
863+
});
864+
865+
805866
it('should call kit.selectPlacements with empty attributes', () => {
806867
const kit: IRoktKit = {
807868
launcher: {

0 commit comments

Comments
 (0)