@segment/analytics-browser-actions-friendbuy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
2
+
3
+ import type { FriendbuyAPI } from '../types'
4
+ import type { Settings } from '../generated-types'
5
+ import type { Payload } from './generated-types'
6
+ import type { AnalyticsPayload, ConvertFun, EventMap } from '@segment/actions-shared'
7
+
8
+ import { COPY, ROOT, mapEvent } from '@segment/actions-shared'
9
+ import { trackSignUpFields } from '@segment/actions-shared'
10
+ import { addName, enjoinInteger, enjoinString, parseDate } from '@segment/actions-shared'
11
+
12
+ export const browserTrackSignUpFields = trackSignUpFields({ requireCustomerId: true, requireEmail: true })
13
+
14
+ // see https://segment.com/docs/config-api/fql/
15
+ export const trackSignUpDefaultSubscription = 'event = "Signed Up"'
16
+
17
+ const trackSignUpPub: EventMap = {
18
+ fields: {
19
+ coupon: { name: 'couponCode' },
20
+ attributionId: COPY,
21
+ referralCode: COPY,
22
+
23
+ // CUSTOMER FIELDS
24
+ customerId: { name: 'id', convert: enjoinString as ConvertFun },
25
+ anonymousID: COPY,
26
+ isNewCustomer: COPY,
27
+ loyaltyStatus: COPY,
28
+ email: COPY,
29
+ firstName: COPY,
30
+ lastName: COPY,
31
+ name: COPY,
32
+ age: { convert: enjoinInteger as ConvertFun },
33
+ birthday: { convert: parseDate as ConvertFun }
34
+ },
35
+ unmappedFieldObject: ROOT
36
+ }
37
+
38
+ const action: BrowserActionDefinition<Settings, FriendbuyAPI, Payload> = {
39
+ title: 'Track Sign Up',
40
+ description: 'Record when a customer signs up for a service.',
41
+ defaultSubscription: trackSignUpDefaultSubscription,
42
+ platform: 'web',
43
+ fields: browserTrackSignUpFields,
44
+
45
+ perform: (friendbuyAPI, { payload }) => {
46
+ addName(payload)
47
+ const friendbuyPayload = mapEvent(trackSignUpPub, payload as unknown as AnalyticsPayload)
48
+ friendbuyAPI.push(['track', 'sign_up', friendbuyPayload, true])
49
+ }
50
+ }
51
+
52
+ export default action
package/src/types.ts ADDED
@@ -0,0 +1,3 @@
1
+ export interface FriendbuyAPI extends Array<unknown> {
2
+ merchantId: string
3
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "baseUrl": "."
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["dist", "**/__tests__"]
9
+ }