Skip to content

Commit

Permalink
Update Ripe web destination (#968)
Browse files Browse the repository at this point in the history
* Update Ripe web destination

- Add new endpoint setting for testing purposes
- Remove alias call
- Update misleading anonymousId descriptions

* Update erroneous default paths

* Set anonymousId in identify call
  • Loading branch information
simpajj authored Jan 23, 2023
1 parent 8e5ef88 commit 2879de3
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 189 deletions.

This file was deleted.

This file was deleted.

46 changes: 0 additions & 46 deletions packages/browser-destinations/src/destinations/ripe/alias/index.ts

This file was deleted.

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

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 @@ -12,7 +12,7 @@ const action: BrowserActionDefinition<Settings, RipeSDK, Payload> = {
anonymousId: {
type: 'string',
required: true,
description: 'The new user ID, if user ID is not set',
description: 'The anonymous id',
label: 'Anonymous ID',
default: { '@path': '$.anonymousId' }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const subscriptions: Subscription[] = [
enabled: true,
subscribe: 'type = "identify"',
mapping: {
anonymousId: {
'@path': '$.anonymousId'
},
userId: {
'@path': '$.userId'
},
Expand Down Expand Up @@ -47,6 +50,7 @@ describe('Ripe.identify', () => {
await event.identify?.(
new Context({
type: 'identify',
anonymousId: 'anonymousId',
userId: 'userId',
traits: {
name: 'Simon'
Expand All @@ -58,6 +62,7 @@ describe('Ripe.identify', () => {
expect.anything(),
expect.objectContaining({
payload: {
anonymousId: 'anonymousId',
userId: 'userId',
traits: {
name: 'Simon'
Expand All @@ -67,6 +72,7 @@ describe('Ripe.identify', () => {
)

expect(window.Ripe.identify).toHaveBeenCalledWith(
expect.stringMatching('anonymousId'),
expect.stringMatching('userId'),
expect.objectContaining({ name: 'Simon' })
)
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
Expand Up @@ -12,7 +12,7 @@ const action: BrowserActionDefinition<Settings, RipeSDK, Payload> = {
anonymousId: {
type: 'string',
required: true,
description: 'The new user ID, if user ID is not set',
description: 'The anonymous id',
label: 'Anonymous ID',
default: { '@path': '$.anonymousId' }
},
Expand All @@ -28,7 +28,7 @@ const action: BrowserActionDefinition<Settings, RipeSDK, Payload> = {
required: false,
description: 'The ID associated groupId',
label: 'Group ID',
default: { '@path': '$.groupId' }
default: { '@path': '$.context.groupId' }
},
traits: {
type: 'object',
Expand All @@ -39,8 +39,9 @@ const action: BrowserActionDefinition<Settings, RipeSDK, Payload> = {
}
},
perform: async (ripe, { payload }) => {
console.log(JSON.stringify(payload, null, 2))
await ripe.setIds(payload.anonymousId, payload.userId, payload.groupId)
return ripe.identify(payload.userId, payload.traits)
return ripe.identify(payload.anonymousId, payload.userId, payload.traits)
}
}

Expand Down
19 changes: 9 additions & 10 deletions packages/browser-destinations/src/destinations/ripe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { initScript } from './init-script'

import page from './page'

import alias from './alias'

const defaultVersion = 'latest'

declare global {
Expand Down Expand Up @@ -46,6 +44,13 @@ export const destination: BrowserDestinationDefinition<Settings, RipeSDK> = {
label: 'API Key',
type: 'string',
required: true
},
endpoint: {
label: 'API Endpoint',
description: `The Ripe API endpoint (do not change this unless you know what you're doing)`,
type: 'string',
format: 'uri',
default: 'https://storage.getripe.com'
}
},

Expand All @@ -54,9 +59,10 @@ export const destination: BrowserDestinationDefinition<Settings, RipeSDK> = {

const { sdkVersion, apiKey } = settings
const version = sdkVersion ?? defaultVersion
const endpoint = settings.endpoint || 'https://storage.getripe.com'

await deps
.loadScript(`https://storage.googleapis.com/sdk.getripe.com/sdk/${version}/sdk.umd.js`)
.loadScript(`${endpoint}/sdk/${version}/sdk.umd.js`)
.catch((err) => console.error('Unable to load Ripe SDK script', err))

await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'Ripe'), 100)
Expand All @@ -66,20 +72,13 @@ export const destination: BrowserDestinationDefinition<Settings, RipeSDK> = {
},

actions: {
alias,
group,
identify,
page,
track
},

presets: [
{
name: 'Alias user',
subscribe: 'type = "alias"',
partnerAction: 'alias',
mapping: defaultValues(alias.fields)
},
{
name: 'Group user',
subscribe: 'type = "group"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function initScript() {
}

window.Ripe = []
;['alias', 'group', 'identify', 'init', 'page', 'setIds', 'track'].forEach(function (method) {
;['group', 'identify', 'init', 'page', 'setIds', 'track'].forEach(function (method) {
window.Ripe[method] = function () {
let args = Array.from(arguments)
args.unshift(method)
Expand Down

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

20 changes: 16 additions & 4 deletions packages/browser-destinations/src/destinations/ripe/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const action: BrowserActionDefinition<Settings, RipeSDK, Payload> = {
anonymousId: {
type: 'string',
required: true,
description: 'The new user ID, if user ID is not set',
description: 'The anonymous id',
label: 'Anonymous ID',
default: { '@path': '$.anonymousId' }
},
Expand All @@ -28,21 +28,33 @@ const action: BrowserActionDefinition<Settings, RipeSDK, Payload> = {
required: false,
description: 'The ID associated groupId',
label: 'Group ID',
default: { '@path': '$.groupId' }
default: { '@path': '$.context.groupId' }
},
category: {
type: 'string',
required: false,
description: 'The category of the page',
label: 'Category',
default: { '@path': '$.category' }
default: {
'@if': {
exists: { '@path': '$.category' },
then: { '@path': '$.category' },
else: { '@path': '$.context.category' }
}
}
},
name: {
type: 'string',
required: false,
description: 'The name of the page',
label: 'Name',
default: { '@path': '$.name' }
default: {
'@if': {
exists: { '@path': '$.name' },
then: { '@path': '$.name' },
else: { '@path': '$.context.name' }
}
}
},
properties: {
type: 'object',
Expand Down

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

Loading

0 comments on commit 2879de3

Please sign in to comment.