Skip to content

Commit

Permalink
APP-86828 Pendo browser destination (#1683)
Browse files Browse the repository at this point in the history
* APP-86828 update pendo browser destination

* APP-86828 set fields to readOnly, will need to test if this works as expected

* APP-86828 change default region to value from label

* APP-86828 update region labels and add jp

* APP-86828 add CNAME configuration support

* APP-86828 add parentAccount field for group()

* APP-86828 remove flushNow call and update identify unit test
  • Loading branch information
wordythebyrd authored Nov 15, 2023
1 parent 6a97cb3 commit b3c039b
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 206 deletions.

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 @@ -46,7 +46,8 @@ describe('Pendo.group', () => {
initialize: jest.fn(),
isReady: jest.fn(),
track: jest.fn(),
identify: jest.fn()
identify: jest.fn(),
flushNow: jest.fn()
}
return Promise.resolve(mockPendo)
})
Expand Down

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
@@ -1,7 +1,7 @@
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import type { PendoSDK, identifyPayload } from '../types'
import type { PendoSDK, PendoOptions } from '../types'

const action: BrowserActionDefinition<Settings, PendoSDK, Payload> = {
title: 'Send Group Event',
Expand All @@ -11,59 +11,62 @@ const action: BrowserActionDefinition<Settings, PendoSDK, Payload> = {
fields: {
visitorId: {
label: 'Visitor ID',
description: 'Pendo Visitor ID. Defaults to Segment userId',
description: 'Pendo Visitor ID. Maps to Segment userId',
type: 'string',
required: true,
default: {
'@path': '$.userId'
}
},
readOnly: true
},
accountId: {
label: 'Account ID',
description: 'Pendo Account ID. This overrides the Pendo Account ID setting',
description: 'Pendo Account ID',
type: 'string',
required: true,
default: { '@path': '$.groupId' }
default: { '@path': '$.groupId' },
readOnly: true
},
accountData: {
label: 'Account Metadata',
description: 'Additional Account data to send',
type: 'object',
required: false
},
parentAccountId: {
label: 'Parent Account ID',
description:
'Pendo Parent Account ID. This overrides the Pendo Parent Account ID setting. Note: Contact Pendo to request enablement of Parent Account feature.',
type: 'string',
required: false
required: false,
default: { '@path': '$.traits' },
readOnly: true
},
parentAccountData: {
label: 'Parent Account Metadata',
description:
'Additional Parent Account data to send. Note: Contact Pendo to request enablement of Parent Account feature.',
type: 'object',
properties: {
id: {
label: 'Parent Account ID',
type: 'string',
required: true
}
},
additionalProperties: true,
default: { '@path': '$.traits.parentAccount' },
required: false
}
},
perform: (pendo, event) => {
const payload: identifyPayload = {
const payload: PendoOptions = {
visitor: {
id: event.payload.visitorId
},
account: {
...event.payload.accountData,
id: event.payload.accountId
}
}
if (event.payload.accountId || event.settings.accountId) {
payload.account = {
id: event.payload.accountId ?? (event.settings.accountId as string),
...event.payload.accountData
}
}
if (event.payload.parentAccountId || event.settings.parentAccountId) {
payload.parentAccount = {
id: (event.payload.parentAccountId as string) ?? (event.settings.parentAccountId as string),
...event.payload.parentAccountData
}

if (event.payload.parentAccountData) {
payload.parentAccount = event.payload.parentAccountData
}

pendo.identify(payload)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const subscriptions: Subscription[] = [
},
visitorData: {
'@path': '$.traits'
},
accountId: {
'@path': '$.context.group_id'
}
}
}
Expand All @@ -26,7 +23,6 @@ const subscriptions: Subscription[] = [
describe('Pendo.identify', () => {
const settings = {
apiKey: 'abc123',
setVisitorIdOnLoad: 'disabled',
region: 'io'
}

Expand All @@ -46,7 +42,8 @@ describe('Pendo.identify', () => {
initialize: jest.fn(),
isReady: jest.fn(),
track: jest.fn(),
identify: jest.fn()
identify: jest.fn(),
flushNow: jest.fn()
}
return Promise.resolve(mockPendo)
})
Expand All @@ -59,15 +56,11 @@ describe('Pendo.identify', () => {
userId: 'testUserId',
traits: {
first_name: 'Jimbo'
},
context: {
group_id: 'company_id_1'
}
})
await identifyAction.identify?.(context)

expect(mockPendo.identify).toHaveBeenCalledWith({
account: { id: 'company_id_1' },
visitor: { first_name: 'Jimbo', id: 'testUserId' }
})
})
Expand Down

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
@@ -1,7 +1,7 @@
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import type { PendoSDK, identifyPayload } from '../types'
import type { PendoSDK, PendoOptions } from '../types'

const action: BrowserActionDefinition<Settings, PendoSDK, Payload> = {
title: 'Send Identify Event',
Expand All @@ -11,74 +11,32 @@ const action: BrowserActionDefinition<Settings, PendoSDK, Payload> = {
fields: {
visitorId: {
label: 'Visitor ID',
description: 'Pendo Visitor ID. Defaults to Segment userId',
description: 'Pendo Visitor ID. Maps to Segment userId',
type: 'string',
required: true,
default: {
'@path': '$.userId'
}
},
readOnly: true
},
visitorData: {
label: 'Visitor Metadata',
description: 'Additional Visitor data to send',
type: 'object',
default: {
'@path': '$.traits'
}
},
accountId: {
label: 'Account ID',
description: 'Pendo Account ID. This overrides the Pendo Account ID setting',
type: 'string',
required: false,
default: {
'@if': {
exists: { '@path': '$.context.group_id' },
then: { '@path': '$.context.group_id' },
else: { '@path': '$.groupId' }
}
}
},
accountData: {
label: 'Account Metadata',
description: 'Additional Account data to send',
type: 'object',
required: false
},
parentAccountId: {
label: 'Parent Account ID',
description:
'Pendo Parent Account ID. This overrides the Pendo Parent Account ID setting. Note: Contact Pendo to request enablement of Parent Account feature.',
type: 'string',
required: false
},
parentAccountData: {
label: 'Parent Account Metadata',
description:
'Additional Parent Account data to send. Note: Contact Pendo to request enablement of Parent Account feature.',
type: 'object',
required: false
},
readOnly: true
}
},
perform: (pendo, event) => {
const payload: identifyPayload = {
const payload: PendoOptions = {
visitor: {
id: event.payload.visitorId,
...event.payload.visitorData
}
}
if (event.payload.accountId || event.settings.accountId) {
payload.account = {
id: (event.payload.accountId as string) ?? (event.settings.accountId as string),
...event.payload.accountData
}
}
if (event.payload.parentAccountId || event.settings.parentAccountId) {
payload.parentAccount = {
id: (event.payload.parentAccountId as string) ?? (event.settings.parentAccountId as string),
...event.payload.parentAccountData
...event.payload.visitorData,
id: event.payload.visitorId
}
}

pendo.identify(payload)
}
}
Expand Down
Loading

0 comments on commit b3c039b

Please sign in to comment.