Skip to content

Commit 98d7246

Browse files
mvedma0405mvedma04005claude
authored
feat: add gwpApproved setting for gift-with-purchase conversions (#2)
* feat: add gwpApproved setting for gift-with-purchase conversions Maps a configured custom event name (or comma-separated list) to a new gwpApproved Pay+ signal, following the same pattern as the other custom event settings: the signal posts { source, type: 'gwpApproved', detail: <event attributes>, trigger } to the embedding plugin. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: rename setting to gwpApprovedEventName + drop drift-prone README settings tables - rename the setting key gwpApproved -> gwpApprovedEventName to match the <signal>EventName convention of the other custom-event settings (nothing has shipped server-side yet, so the rename is free) - replace the README per-setting tables with a drift-proof description of the naming convention; the dashboard fields are self-describing Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: mvedma04005 <mani.vedma@rokt.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 651fdd5 commit 98d7246

3 files changed

Lines changed: 27 additions & 22 deletions

File tree

README.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ The kit loads alongside the mParticle web SDK and receives the events your appli
1010
| :-- | :-- |
1111
| `initiated` | the kit initializes (application loaded) |
1212
| `stepComplete` | a configured funnel-step screen is viewed |
13-
| `approved` | the configured conversion event or screen |
14-
| `pending`, `loggedIn`, `accountCreated`, `offerSaved`, `purchaseCompleted`, `formSubmitted`, `pendingSuccess`, `close`, `removeLoadingOverlay` | the matching configured event or screen |
13+
| `approved` | the configured conversion event |
14+
| every other Pay+ signal (`pending`, `accountCreated`, `purchaseCompleted`, ...) | the matching configured custom event |
1515

1616
## Configuration
1717

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

2222
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.
2323

24-
Page view setting:
25-
26-
| Setting | Maps to |
27-
| :-- | :-- |
28-
| `progressionScreenNames` | `stepComplete` (one per listed screen) |
29-
30-
Custom event settings:
31-
32-
| Setting | Maps to |
33-
| :-- | :-- |
34-
| `approvedEventName` | `approved` |
35-
| `pendingEventName` | `pending` |
36-
| `loggedInEventName` | `loggedIn` |
37-
| `accountCreatedEventName` | `accountCreated` |
38-
| `offerSavedEventName` | `offerSaved` |
39-
| `purchaseCompletedEventName` | `purchaseCompleted` |
40-
| `formSubmittedEventName` | `formSubmitted` |
41-
| `pendingSuccessEventName` | `pendingSuccess` |
42-
| `closeEventName` | `close` |
43-
| `removeLoadingOverlayEventName` | `removeLoadingOverlay` |
24+
`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.
4425

4526
`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.
4627

src/RoktPayPlus-Kit.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const SIGNALS = {
5555
PENDING_SUCCESS: 'pendingSuccess',
5656
CLOSE: 'close',
5757
REMOVE_LOADING_OVERLAY: 'removeLoadingOverlay',
58+
GWP_APPROVED: 'gwpApproved',
5859
} as const;
5960

6061
const DEFAULT_CONVERSION_EVENT_NAME = 'conversion';
@@ -71,6 +72,7 @@ const EVENT_SETTING_TO_SIGNAL: ReadonlyArray<{ setting: keyof RoktPayPlusKitSett
7172
{ setting: 'pendingSuccessEventName', signal: SIGNALS.PENDING_SUCCESS },
7273
{ setting: 'closeEventName', signal: SIGNALS.CLOSE },
7374
{ setting: 'removeLoadingOverlayEventName', signal: SIGNALS.REMOVE_LOADING_OVERLAY },
75+
{ setting: 'gwpApprovedEventName', signal: SIGNALS.GWP_APPROVED },
7476
];
7577

7678
// ============================================================
@@ -91,6 +93,8 @@ interface RoktPayPlusKitSettings {
9193
closeEventName?: string;
9294
removeLoadingOverlayEventName?: string;
9395
conversionEventName?: string;
96+
// Custom event name(s) that signal a gift-with-purchase conversion.
97+
gwpApprovedEventName?: string;
9498
}
9599

96100
interface KitConfig {

test/src/RoktPayPlus-Kit.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ describe('RoktPayPlusKit', () => {
121121
});
122122
});
123123

124+
describe('gwpApprovedEventName setting', () => {
125+
it('emits gwpApproved for the configured custom event, with the event attributes as detail', () => {
126+
const kit = new RoktPayPlusKit();
127+
kit.init({ gwpApprovedEventName: 'Gift Purchase Completed' });
128+
kit.process(customEvent('Gift Purchase Completed', { sku: 'gwp-123', amount: '49.99' }));
129+
const gwp = ofType('gwpApproved');
130+
expect(gwp.length).toBe(1);
131+
expect(gwp[0].message.detail).toEqual({ sku: 'gwp-123', amount: '49.99' });
132+
expect(gwp[0].message.trigger).toBe("logEvent('Gift Purchase Completed')");
133+
expect(ofType('approved').length).toBe(0);
134+
});
135+
136+
it('suppresses the default conversion fallback once gwpApprovedEventName is configured', () => {
137+
const kit = new RoktPayPlusKit();
138+
kit.init({ gwpApprovedEventName: 'Gift Purchase Completed' });
139+
kit.process(customEvent('conversion'));
140+
expect(ofType('approved').length).toBe(0);
141+
});
142+
});
143+
124144
describe('embedding guard', () => {
125145
it('makes no postMessage calls when not framed (parent === self)', () => {
126146
// Restore the real window.parent so the page looks top-level (jsdom: parent === window).

0 commit comments

Comments
 (0)