Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1flow web sdk event update #2019

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export function initScript({ projectApiKey }) {
r.setAttribute('data-api-key', k)
r.src = t
a.appendChild(r)
})(window, document, setTimeout, 'https://cdn-development.1flow.ai/js-sdk/1flow.js', apiKey)
})(window, document, setTimeout, 'https://1flow.app/js/1flow.js', apiKey)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ type _1FlowApi = {

type _1FlowFunction = (method: method, ...args: unknown[]) => void

export type _1Flow = _1FlowFunction & _1FlowApi
export type _1flow = _1FlowFunction & _1FlowApi

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

const action: BrowserActionDefinition<Settings, _1Flow, Payload> = {
const action: BrowserActionDefinition<Settings, _1flow, Payload> = {
title: 'Identify User',
description: 'Create or update a user in 1Flow.',
defaultSubscription: 'type = "identify"',
Expand All @@ -18,15 +18,6 @@ const action: BrowserActionDefinition<Settings, _1Flow, Payload> = {
'@path': '$.userId'
}
},
anonymousId: {
description: 'An anonymous identifier for the user.',
label: 'Anonymous ID',
type: 'string',
required: false,
default: {
'@path': '$.anonymousId'
}
},
traits: {
description: "The user's custom attributes.",
label: 'Custom Attributes',
Expand All @@ -36,53 +27,12 @@ const action: BrowserActionDefinition<Settings, _1Flow, Payload> = {
default: {
'@path': '$.traits'
}
},
first_name: {
description: "The user's first name.",
label: 'First Name',
type: 'string',
required: false,
default: {
'@path': '$.traits.first_name'
}
},
last_name: {
description: "The user's last name.",
label: 'First Name',
type: 'string',
required: false,
default: {
'@path': '$.traits.last_name'
}
},
phone: {
description: "The user's phone number.",
label: 'Phone Number',
type: 'string',
required: false,
default: {
'@path': '$.traits.phone'
}
},

email: {
description: "The user's email address.",
label: 'Email Address',
type: 'string',
required: false,
default: {
'@path': '$.traits.email'
}
}
},
perform: (_1Flow, event) => {
const { userId, anonymousId, traits, first_name, last_name, phone, email } = event.payload
_1Flow('identify', userId, anonymousId, {
...traits,
first_name: first_name,
last_name: last_name,
phone: phone,
email: email
perform: (_1flow, event) => {
const { userId, traits } = event.payload
_1flow('identify', userId, {
...traits
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/browser-destinations/destinations/1flow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import type { BrowserDestinationDefinition } from '@segment/browser-destination-
import { browserDestination } from '@segment/browser-destination-runtime/shim'
import trackEvent from './trackEvent'
import { initScript } from './1flow'
import { _1Flow } from './api'
import { _1flow } from './api'
import identifyUser from './identifyUser'
import { defaultValues } from '@segment/actions-core'
declare global {
interface Window {
_1Flow: _1Flow
_1flow: _1flow
}
}

export const destination: BrowserDestinationDefinition<Settings, _1Flow> = {
export const destination: BrowserDestinationDefinition<Settings, _1flow> = {
name: '1Flow Web (Actions)',
slug: 'actions-1flow',
mode: 'device',
Expand Down Expand Up @@ -46,8 +46,8 @@ export const destination: BrowserDestinationDefinition<Settings, _1Flow> = {
initialize: async ({ settings }, deps) => {
const projectApiKey = settings.projectApiKey
initScript({ projectApiKey })
await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, '_1Flow'), 100)
return window._1Flow
await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, '_1flow'), 100)
return window._1flow
},
actions: {
trackEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
import { _1Flow } from '../api'
import { _1flow } from '../api'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'

const action: BrowserActionDefinition<Settings, _1Flow, Payload> = {
const action: BrowserActionDefinition<Settings, _1flow, Payload> = {
title: 'Track Event',
description: 'Submit an event to 1Flow.',
defaultSubscription: 'type = "track"',
Expand Down Expand Up @@ -46,9 +46,9 @@ const action: BrowserActionDefinition<Settings, _1Flow, Payload> = {
}
}
},
perform: (_1Flow, event) => {
perform: (_1flow, event) => {
const { event_name, userId, anonymousId, properties } = event.payload
_1Flow('track', event_name, {
_1flow('track', event_name, {
userId: userId,
anonymousId: anonymousId,
properties: properties
Expand Down