Skip to content
Merged
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
25 changes: 3 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The kit loads alongside the mParticle web SDK and receives the events your appli
| :-- | :-- |
| `initiated` | the kit initializes (application loaded) |
| `stepComplete` | a configured funnel-step screen is viewed |
| `approved` | the configured conversion event or screen |
| `pending`, `loggedIn`, `accountCreated`, `offerSaved`, `purchaseCompleted`, `formSubmitted`, `pendingSuccess`, `close`, `removeLoadingOverlay` | the matching configured event or screen |
| `approved` | the configured conversion event |
| every other Pay+ signal (`pending`, `accountCreated`, `purchaseCompleted`, ...) | the matching configured custom event |

## Configuration

Expand All @@ -21,26 +21,7 @@ Funnel progression is driven by **page view events**, matched on the screen name

The screen name is read from the page view's `screen_name` attribute (falling back to the page name when that attribute is absent), so the names you list in `progressionScreenNames` are the `screen_name` values your application sends.

Page view setting:

| Setting | Maps to |
| :-- | :-- |
| `progressionScreenNames` | `stepComplete` (one per listed screen) |

Custom event settings:

| Setting | Maps to |
| :-- | :-- |
| `approvedEventName` | `approved` |
| `pendingEventName` | `pending` |
| `loggedInEventName` | `loggedIn` |
| `accountCreatedEventName` | `accountCreated` |
| `offerSavedEventName` | `offerSaved` |
| `purchaseCompletedEventName` | `purchaseCompleted` |
| `formSubmittedEventName` | `formSubmitted` |
| `pendingSuccessEventName` | `pendingSuccess` |
| `closeEventName` | `close` |
| `removeLoadingOverlayEventName` | `removeLoadingOverlay` |
`progressionScreenNames` lists the screens that emit `stepComplete`. Each custom-event setting maps an event name to the Pay+ signal of the same name: `approvedEventName` maps to `approved`, `purchaseCompletedEventName` maps to `purchaseCompleted`, and so on. The full list of fields, each with its description, appears in the connection settings in the mParticle dashboard.

`initiated` is emitted automatically when the kit initializes. If no settings are provided, the kit applies a default mapping: each page view is treated as a funnel step, and a custom event named `conversion` is treated as the approval.

Expand Down
4 changes: 4 additions & 0 deletions src/RoktPayPlus-Kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const SIGNALS = {
PENDING_SUCCESS: 'pendingSuccess',
CLOSE: 'close',
REMOVE_LOADING_OVERLAY: 'removeLoadingOverlay',
GWP_APPROVED: 'gwpApproved',
} as const;

const DEFAULT_CONVERSION_EVENT_NAME = 'conversion';
Expand All @@ -71,6 +72,7 @@ const EVENT_SETTING_TO_SIGNAL: ReadonlyArray<{ setting: keyof RoktPayPlusKitSett
{ setting: 'pendingSuccessEventName', signal: SIGNALS.PENDING_SUCCESS },
{ setting: 'closeEventName', signal: SIGNALS.CLOSE },
{ setting: 'removeLoadingOverlayEventName', signal: SIGNALS.REMOVE_LOADING_OVERLAY },
{ setting: 'gwpApprovedEventName', signal: SIGNALS.GWP_APPROVED },
];

// ============================================================
Expand All @@ -91,6 +93,8 @@ interface RoktPayPlusKitSettings {
closeEventName?: string;
removeLoadingOverlayEventName?: string;
conversionEventName?: string;
// Custom event name(s) that signal a gift-with-purchase conversion.
gwpApprovedEventName?: string;
}

interface KitConfig {
Expand Down
20 changes: 20 additions & 0 deletions test/src/RoktPayPlus-Kit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ describe('RoktPayPlusKit', () => {
});
});

describe('gwpApprovedEventName setting', () => {
it('emits gwpApproved for the configured custom event, with the event attributes as detail', () => {
const kit = new RoktPayPlusKit();
kit.init({ gwpApprovedEventName: 'Gift Purchase Completed' });
kit.process(customEvent('Gift Purchase Completed', { sku: 'gwp-123', amount: '49.99' }));
const gwp = ofType('gwpApproved');
expect(gwp.length).toBe(1);
expect(gwp[0].message.detail).toEqual({ sku: 'gwp-123', amount: '49.99' });
expect(gwp[0].message.trigger).toBe("logEvent('Gift Purchase Completed')");
expect(ofType('approved').length).toBe(0);
});

it('suppresses the default conversion fallback once gwpApprovedEventName is configured', () => {
const kit = new RoktPayPlusKit();
kit.init({ gwpApprovedEventName: 'Gift Purchase Completed' });
kit.process(customEvent('conversion'));
expect(ofType('approved').length).toBe(0);
});
});

describe('embedding guard', () => {
it('makes no postMessage calls when not framed (parent === self)', () => {
// Restore the real window.parent so the page looks top-level (jsdom: parent === window).
Expand Down
Loading