react-marketing-tools 0.2.7 → 0.2.9
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/README.md +8 -64
- package/dist/index.d.ts +144 -5
- package/dist/lib/types.d.ts +2 -1
- package/dist/manifest.json +2 -2
- package/dist/react-marketing-tools.es.js +2676 -2659
- package/dist/react-marketing-tools.umd.js +10 -10
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
React Marketing Tools are a set of tools to make it easier for you to implement analytics and track user journeys, interactions throughout your App. using dataLayer/Google Tag Manager, GA4 fetch directly or coming soon facebook pixel.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
[React Marketing Tools Demo](https://codepen.io/roryfn/pen/OJBGvMG)
|
|
7
|
+
[Detailed Blog post on React Marketing Tools Implementation](https://blog.heyrory.com/google-analytics-4-google-tag-manager)
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
# PR's
|
|
@@ -32,7 +32,7 @@ COMING SOON: [React Marketing Tools Demo](https://)
|
|
|
32
32
|
TOKENS are optional
|
|
33
33
|
const TOKENS: Tokens = {
|
|
34
34
|
|
|
35
|
-
// if
|
|
35
|
+
// if withServerLocationInfo is true you must supply this token.
|
|
36
36
|
IP_INFO_TOKEN: 'SOME_TOKEN',
|
|
37
37
|
|
|
38
38
|
// if analyticsType = analyticsPlatform.GOOGLE the below tokens must be supplied.
|
|
@@ -128,6 +128,8 @@ COMING SOON: [React Marketing Tools Demo](https://)
|
|
|
128
128
|
|
|
129
129
|
const sendAnalyticsEvent = async () => {
|
|
130
130
|
const eventNameInfo: EventNameInfo = {
|
|
131
|
+
// If this is not passed in the event name will be a combination of actionPrefix & globalAppEvent
|
|
132
|
+
// J_UNAUTHENTICATED
|
|
131
133
|
eventName: 'Welcome Landing',
|
|
132
134
|
actionPrefix: eventActionPrefixList.JOURNEY,
|
|
133
135
|
globalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
|
|
@@ -152,6 +154,8 @@ COMING SOON: [React Marketing Tools Demo](https://)
|
|
|
152
154
|
setCount(countActual)
|
|
153
155
|
|
|
154
156
|
const eventNameInfo: EventNameInfo = {
|
|
157
|
+
// If this is not passed in the event name will be a combination of actionPrefix & globalAppEvent
|
|
158
|
+
// I_AUTHENTICATED
|
|
155
159
|
eventName: 'count button click',
|
|
156
160
|
actionPrefix: eventActionPrefixList.INTERACTION,
|
|
157
161
|
globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
|
|
@@ -219,64 +223,4 @@ COMING SOON: [React Marketing Tools Demo](https://)
|
|
|
219
223
|
```
|
|
220
224
|
|
|
221
225
|
## Usage without Provider
|
|
222
|
-
|
|
223
|
-
import { useState, useEffect, useCallback } from 'react'
|
|
224
|
-
import { trackAnalyticsEvent, analyticsPlatform } from "react-marketing-tools";
|
|
225
|
-
import { EventNameInfo, TrackAnalyticsEventOptions } from './lib/types'
|
|
226
|
-
|
|
227
|
-
const WelcomePage = () => {
|
|
228
|
-
useEffect(function appLoadPageLandingWelcome() {
|
|
229
|
-
const sendAnalyticsEvent = async () => {
|
|
230
|
-
const eventNameInfo: EventNameInfo = {
|
|
231
|
-
actionPrefix: eventActionPrefixList.JOURNEY,
|
|
232
|
-
description: 'Welcome Landing',
|
|
233
|
-
globalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const trackingData: TrackAnalyticsEventOptions = {
|
|
237
|
-
data: {},
|
|
238
|
-
eventNameInfo,
|
|
239
|
-
analyticsType: analyticsPlatform.DATALAYER_PUSH,
|
|
240
|
-
dataLayerCheck: true,
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
await trackAnalyticsEvent(trackingData)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
sendAnalyticsEvent()
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
const handleButtonClick = async () => {
|
|
250
|
-
const countActual = count + 1
|
|
251
|
-
setCount(countActual)
|
|
252
|
-
|
|
253
|
-
const eventNameInfo: EventNameInfo = {
|
|
254
|
-
eventName: 'count button click',
|
|
255
|
-
actionPrefix: eventActionPrefixList.INTERACTION,
|
|
256
|
-
globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
|
|
257
|
-
previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const trackingData: TrackAnalyticsEventOptions = {
|
|
261
|
-
data: {
|
|
262
|
-
count: countActual,
|
|
263
|
-
firstName: 'bob',
|
|
264
|
-
lastName: 'yeah nah',
|
|
265
|
-
email: 'yeahnah@gmail.com',
|
|
266
|
-
},
|
|
267
|
-
eventNameInfo,
|
|
268
|
-
analyticsType: analyticsPlatform.DATALAYER_PUSH,
|
|
269
|
-
consoleLogData: {
|
|
270
|
-
showJourneyPropsPayload: true
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
await trackAnalyticsEvent(trackingData)
|
|
275
|
-
}
|
|
276
|
-
...
|
|
277
|
-
|
|
278
|
-
return (
|
|
279
|
-
...
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
```
|
|
226
|
+
> To view implementation and usage without the React Context/Provider visit this [codepen](https://codepen.io/roryfn/pen/OJBGvMG)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,144 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
// react-marketing-tools.d.ts
|
|
2
|
+
|
|
3
|
+
declare module 'react-marketing-tools' {
|
|
4
|
+
// Event types
|
|
5
|
+
export type Event = {
|
|
6
|
+
name: string
|
|
7
|
+
params: Record<AllowedTypes, AllowedTypes>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// GooglePayload type - Represents the payload structure for Google Analytics
|
|
11
|
+
export type GooglePayload = {
|
|
12
|
+
non_personalized_ads: boolean
|
|
13
|
+
client_id: string
|
|
14
|
+
user_id: string
|
|
15
|
+
user_properties: {
|
|
16
|
+
user_id: string
|
|
17
|
+
user_type: string
|
|
18
|
+
client_id: string
|
|
19
|
+
}
|
|
20
|
+
events: Event[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// EventNameInfo type - Information about a specific analytics event
|
|
24
|
+
export type EventNameInfo = {
|
|
25
|
+
eventName: string
|
|
26
|
+
description?: string
|
|
27
|
+
actionPrefix: string
|
|
28
|
+
globalAppEvent: string
|
|
29
|
+
previousGlobalAppEvent?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// AllowedTypes type - Union type for allowed parameter types in events
|
|
33
|
+
export type AllowedTypes = string | number
|
|
34
|
+
|
|
35
|
+
// TrackAnalyticsEventOptions type - Options for tracking an analytics event
|
|
36
|
+
export type TrackAnalyticsEventOptions = {
|
|
37
|
+
data: Record<AllowedTypes, AllowedTypes>
|
|
38
|
+
eventNameInfo: EventNameInfo
|
|
39
|
+
analyticsType: string
|
|
40
|
+
userDataToHashKeyArray: Array<string> | null
|
|
41
|
+
dataLayerCheck: boolean
|
|
42
|
+
consoleLogData?: object
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// GlobalVars type - Represents global variables in analytics tracking
|
|
46
|
+
export type GlobalVars = {
|
|
47
|
+
app: string
|
|
48
|
+
device_category?: string | undefined
|
|
49
|
+
device_os?: string | undefined
|
|
50
|
+
device_browser?: string | undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// DataLayer type - Represents the data layer for analytics events
|
|
54
|
+
export type DataLayer = {
|
|
55
|
+
event: string
|
|
56
|
+
globalVars: GlobalVars
|
|
57
|
+
journeyProps: Record<any, any>
|
|
58
|
+
userProps: Record<any, any>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ConsoleLogData type - Options for console logging analytics data
|
|
62
|
+
export type ConsoleLogData = {
|
|
63
|
+
showGlobalVars?: boolean
|
|
64
|
+
showJourneyPropsPayload?: boolean
|
|
65
|
+
showUserProps?: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// AnalyticsTrackerDataOptions interface - Options for analytics tracking
|
|
69
|
+
export interface AnalyticsTrackerDataOptions {
|
|
70
|
+
consoleLogData: ConsoleLogData | null
|
|
71
|
+
data: Record<any, any>
|
|
72
|
+
eventName: string
|
|
73
|
+
globalAppEvent: string
|
|
74
|
+
userDetails: Record<any, any>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// HandleDataLayerPushOptions type - Options for handling data layer push
|
|
78
|
+
export interface HandleDataLayerPushOptions
|
|
79
|
+
extends AnalyticsTrackerDataOptions {
|
|
80
|
+
dataLayerCheck: boolean
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Ga4GoogleAnalyticsEventTracking type - Options for GA4 Google Analytics event tracking
|
|
84
|
+
export type Ga4GoogleAnalyticsEventTracking = AnalyticsTrackerDataOptions
|
|
85
|
+
|
|
86
|
+
// Platform type - Union type for supported analytics platforms
|
|
87
|
+
export type Platform = 'GOOGLE' | 'FACEBOOK' | 'DATALAYER_PUSH'
|
|
88
|
+
|
|
89
|
+
// Tokens type - Represents tokens used in the analytics configuration
|
|
90
|
+
export type Tokens = {
|
|
91
|
+
IP_INFO_TOKEN?: string
|
|
92
|
+
GA4_PUBLIC_API_SECRET?: string
|
|
93
|
+
GA4_PUBLIC_MEASUREMENT_ID?: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Config type - Represents the configuration for analytics tracking
|
|
97
|
+
export type Config = {
|
|
98
|
+
TOKENS?: Tokens
|
|
99
|
+
appName: string
|
|
100
|
+
appSessionCookieName: string
|
|
101
|
+
withDeviceInfo?: boolean
|
|
102
|
+
includeUserKeys: Array<string>
|
|
103
|
+
showMissingUserAttributesInConsole: boolean | undefined
|
|
104
|
+
withServerLocationInfo: boolean | undefined
|
|
105
|
+
eventActionPrefixList: Record<string, string>
|
|
106
|
+
analyticsGlobalEventActionList: Record<string, string>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// BuildConfigOptions type - Options for building the analytics configuration
|
|
110
|
+
export type BuildConfigOptions = {
|
|
111
|
+
appName: string
|
|
112
|
+
appSessionCookieName: string
|
|
113
|
+
eventActionPrefix?: Record<string, string>
|
|
114
|
+
globalEventActionList?: Record<string, string>
|
|
115
|
+
includeUserKeys?: boolean
|
|
116
|
+
showMissingUserAttributesInConsole?: boolean
|
|
117
|
+
TOKENS?: Tokens
|
|
118
|
+
withDeviceInfo?: boolean
|
|
119
|
+
withServerLocationInfo?: boolean
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Function declarations
|
|
123
|
+
export const analyticsPlatform: {
|
|
124
|
+
[key in Platform]: Platform
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Function to log supported analytics platforms
|
|
128
|
+
export const showMeBuildInAnalyticsPlatform: () => void
|
|
129
|
+
|
|
130
|
+
export const analyticsEventActionPrefixList: Record<string, string>
|
|
131
|
+
|
|
132
|
+
// Function to log built-in event action prefix list
|
|
133
|
+
export const showMeBuildInEventActionPrefixList: () => void
|
|
134
|
+
|
|
135
|
+
export const analyticsGlobalEventActionList: Record<string, string>
|
|
136
|
+
|
|
137
|
+
// Function to log built-in global event action list
|
|
138
|
+
export const showMeBuildInGlobalEventActionList: () => void
|
|
139
|
+
|
|
140
|
+
export let config: Config
|
|
141
|
+
|
|
142
|
+
// Function to build the analytics configuration
|
|
143
|
+
export const buildConfig: (options: BuildConfigOptions) => void
|
|
144
|
+
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TrackAnalyticsEventOptions } from './analytics/types';
|
|
2
|
+
import { Platform } from './buildConfig/types';
|
|
2
3
|
export declare type ProviderStateProps = {
|
|
3
4
|
appName: string;
|
|
4
5
|
appSessionCookieName: string;
|