Skip to content
Draft
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
2 changes: 1 addition & 1 deletion dist/mparticle.common.js

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

2 changes: 1 addition & 1 deletion dist/mparticle.esm.js

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

4 changes: 4 additions & 0 deletions dist/mparticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9623,6 +9623,10 @@ var mParticle = (function () {
return Promise.resolve({});
}
try {
var preSelectionAttributes = this.launcher.preSelectionCallback();
console.log('[RoktManager] preSelectionAttributes', preSelectionAttributes);
options.attributes = __assign(__assign({}, options.attributes), preSelectionAttributes);
console.log('[RoktManager] selectPlacement attributes', options.attributes);
return this.launcher.selectPlacements(options);
} catch (error) {
return Promise.reject(error instanceof Error ? error : new Error('Unknown error occurred'));
Expand Down
5 changes: 5 additions & 0 deletions src/roktManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface IRoktSelection {

export interface IRoktLauncher {
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
preSelectionCallback: () => IRoktPartnerAttributes;
Copy link
Author

Choose a reason for hiding this comment

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

maybe a better name would be preSelectHook

}

export interface IRoktMessage {
Expand Down Expand Up @@ -48,6 +49,10 @@ export default class RoktManager {
}

try {
const preSelectionAttributes = this.launcher.preSelectionCallback();
console.log('[RoktManager] preSelectionAttributes', preSelectionAttributes);
options.attributes = { ...options.attributes, ...preSelectionAttributes };
console.log('[RoktManager] selectPlacement attributes', options.attributes);
return this.launcher.selectPlacements(options);
} catch (error) {
return Promise.reject(error instanceof Error ? error : new Error('Unknown error occurred'));
Expand Down
12 changes: 8 additions & 4 deletions test/jest/roktManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('RoktManager', () => {

it('should process the message queue if a launcher is attached', () => {
const launcher: IRoktLauncher = {
selectPlacements: jest.fn()
selectPlacements: jest.fn(),
preSelectionCallback: jest.fn()
};

roktManager.selectPlacements({} as IRoktSelectPlacementsOptions);
Expand All @@ -45,7 +46,8 @@ describe('RoktManager', () => {
describe('#selectPlacements', () => {
it('should call launcher.selectPlacements with empty attributes', () => {
const launcher: IRoktLauncher = {
selectPlacements: jest.fn()
selectPlacements: jest.fn(),
preSelectionCallback: jest.fn()
};

roktManager.attachLauncher(launcher);
Expand All @@ -59,7 +61,8 @@ describe('RoktManager', () => {

it('should call launcher.selectPlacements with passed in attributes', () => {
const launcher: IRoktLauncher = {
selectPlacements: jest.fn()
selectPlacements: jest.fn(),
preSelectionCallback: jest.fn()
};

roktManager.attachLauncher(launcher);
Expand Down Expand Up @@ -93,7 +96,8 @@ describe('RoktManager', () => {

it('should process queued selectPlacements calls once the launcher is attached', () => {
const launcher: IRoktLauncher = {
selectPlacements: jest.fn()
selectPlacements: jest.fn(),
preSelectionCallback: jest.fn()
};

const options = {
Expand Down