@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.
- package/package.json +21 -0
- package/src/__tests__/index.test.ts +38 -0
- package/src/generated-types.ts +8 -0
- package/src/index.ts +91 -0
- package/src/trackCustomEvent/__tests__/index.test.ts +98 -0
- package/src/trackCustomEvent/generated-types.ts +30 -0
- package/src/trackCustomEvent/index.ts +49 -0
- package/src/trackCustomer/__tests__/index.test.ts +196 -0
- package/src/trackCustomer/generated-types.ts +74 -0
- package/src/trackCustomer/index.ts +51 -0
- package/src/trackPage/__tests__/index.test.ts +63 -0
- package/src/trackPage/generated-types.ts +16 -0
- package/src/trackPage/index.ts +58 -0
- package/src/trackPurchase/__tests__/index.test.ts +211 -0
- package/src/trackPurchase/generated-types.ts +91 -0
- package/src/trackPurchase/index.ts +85 -0
- package/src/trackSignUp/__tests__/index.test.ts +92 -0
- package/src/trackSignUp/generated-types.ts +62 -0
- package/src/trackSignUp/index.ts +52 -0
- package/src/types.ts +3 -0
- package/tsconfig.json +9 -0
|
@@ -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