Skip to content

Commit

Permalink
Wisepops - Support for new goal tracking function (#1998)
Browse files Browse the repository at this point in the history
* Update Wisepops loader URL

* Update URLs

* Fix lint

* WIS-3633 Update Wisepops segment destination for new goal tracking (#5)

* WIS-3633 Declare revenue in object if new goal

* WIS-3633 Update generated types

* WIS-3633 Remove default goal identifier (#6)

* WIS-3633 Declare revenue in object if new goal

* WIS-3633 Update generated types

* WIS-3633 Remove default goal identifier

---------

Co-authored-by: clementai <git@clement.ai>
Co-authored-by: Clément Aigreault <6172122+clementai@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 22, 2024
1 parent 92b8c5c commit 6fc6fde
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ export const destination: BrowserDestinationDefinition<Settings, Wisepops> = {
mapping: defaultValues(trackEvent.fields),
type: 'automatic'
},
{
name: trackGoal.title,
subscribe: trackGoal.defaultSubscription!,
partnerAction: 'trackGoal',
mapping: defaultValues(trackGoal.fields),
type: 'automatic'
},
{
name: trackPage.title,
subscribe: trackPage.defaultSubscription!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Wisepops.trackGoal', () => {
subscribe: trackGoalObject.defaultSubscription!,
mapping: {
goalName: {
'@path': '$.event'
'@path': '$.properties.goalName'
},
goalRevenue: {
'@path': '$.properties.revenue'
Expand All @@ -28,7 +28,7 @@ describe('Wisepops.trackGoal', () => {
}
]

test('named goal with revenue', async () => {
test('old named goal with revenue', async () => {
const [trackGoal] = await wisepopsDestination({
websiteId: '1234567890',
subscriptions
Expand All @@ -42,11 +42,35 @@ describe('Wisepops.trackGoal', () => {
type: 'track',
event: 'Order Completed',
properties: {
goalName: 'Order Completed',
revenue: 15
}
})
trackGoal.track?.(context)

expect(window.wisepops.q.push).toHaveBeenCalledWith(['goal', 'Order Completed', 15])
})

test('new goal with revenue', async () => {
const [trackGoal] = await wisepopsDestination({
websiteId: '1234567890',
subscriptions
})
expect(trackGoal).toBeDefined()

await trackGoal.load(Context.system(), {} as Analytics)
jest.spyOn(window.wisepops.q as any, 'push')

const context = new Context({
type: 'track',
event: 'Order Completed',
properties: {
goalName: 'yhqnj9RTF3Fk6TnTmRW6vhxiugipbUKc',
revenue: 15
}
})
trackGoal.track?.(context)

expect(window.wisepops.q.push).toHaveBeenCalledWith(['goal', 'yhqnj9RTF3Fk6TnTmRW6vhxiugipbUKc', {revenue: 15}])
})
})

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import type { Wisepops } from '../types'

// Change from unknown to the partner SDK types
const action: BrowserActionDefinition<Settings, Wisepops, Payload> = {
title: 'Track Goal',
description: '[Track goals and revenue](https://support.wisepops.com/article/mx3z8na6yb-set-up-goal-tracking) to know which campaigns are generating the most value.',
defaultSubscription: 'type = "track" and event = "Order Completed"',
platform: 'web',
fields: {
goalName: {
description: 'The name of the goal to send to Wisepops.',
label: 'Goal Name',
description: 'This is a 32-character identifier, visible when you create the JS goal in Wisepops.',
label: 'Goal Identifier',
type: 'string',
required: false,
default: {
'@path': '$.event'
}
},
goalRevenue: {
description: 'The revenue associated with the goal.',
Expand All @@ -30,7 +26,14 @@ const action: BrowserActionDefinition<Settings, Wisepops, Payload> = {
},
},
perform: (wisepops, event) => {
wisepops('goal', event.payload.goalName, event.payload.goalRevenue);
let revenue = null;
if (['string', 'number'].includes(typeof event.payload.goalRevenue) && !Number.isNaN(Number(event.payload.goalRevenue))) {
revenue = Number(event.payload.goalRevenue);
}
if (typeof event.payload.goalName === 'string' && /^[a-zA-Z0-9]{32}$/.test(event.payload.goalName)) {
revenue = {revenue};
}
wisepops('goal', event.payload.goalName, revenue);
}
}

Expand Down

0 comments on commit 6fc6fde

Please sign in to comment.