react-marketing-tools 0.0.1
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 +193 -0
- package/dist/react-marketing-tools.es.js +48598 -0
- package/dist/react-marketing-tools.umd.js +46 -0
- package/package.json +79 -0
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
|
|
2
|
+
# React Marketing Tools [](https://badge.fury.io/js/)
|
|
3
|
+
|
|
4
|
+
[React Marketing Tools Demo](https://)
|
|
5
|
+
|
|
6
|
+
React Marketing Tools are a set of tools to make it easier to implement and manage analytics in your App like dataLayer/Google Tag Manager, GA4 & facebook pixel.
|
|
7
|
+
|
|
8
|
+
# PR's
|
|
9
|
+
- Have a look at the [PR template doc](https://github.com/bronz3beard/react-marketing-tools/blob/main/docs) for best approach to getting your pr merged.
|
|
10
|
+
|
|
11
|
+
# Usage and setup examples.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Setup configuration
|
|
15
|
+
- Setting up config without provider is also an option, in this case you will only need to import _buildConfig_
|
|
16
|
+
```js
|
|
17
|
+
import React from 'react'
|
|
18
|
+
import ReactDOM from 'react-dom/client'
|
|
19
|
+
import { ReactMarketingProvider, buildConfig } from 'react-marketing-tools';
|
|
20
|
+
import App from './App'
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
TOKENS are optional
|
|
24
|
+
const TOKENS = {
|
|
25
|
+
|
|
26
|
+
// if withDeviceInfo is true you must supply this token.
|
|
27
|
+
IP_INFO_TOKEN: 'SOME_TOKEN',
|
|
28
|
+
|
|
29
|
+
// if analyticsType = analyticsPlatform.GOOGLE the below tokens must be supplied.
|
|
30
|
+
GA4_PUBLIC_API_SECRET: 'SOME_TOKEN',
|
|
31
|
+
PUBLIC_MEASUREMENT_ID: 'SOME_TOKEN',
|
|
32
|
+
}
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// These are the keys for the values you want to include from your user data
|
|
36
|
+
// these must be included for any user data to be collected by analytics event if user data is hardcoded when passed in.
|
|
37
|
+
const includeUserKeys = [
|
|
38
|
+
'firstName',
|
|
39
|
+
'lastName',
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const analyticsConfig = {
|
|
43
|
+
appName: 'my-awesome-app', // required
|
|
44
|
+
eventActionPrefix: { // this will extend the default values of eventActionPrefix
|
|
45
|
+
ACTION: 'ACTION',
|
|
46
|
+
OTHER_EVENT_NAME_TYPE: 'OTHER_EVENT_NAME_TYPE'
|
|
47
|
+
},
|
|
48
|
+
globalEventActionList: { // this will extend the default values of globalEventActionList
|
|
49
|
+
SIGN_IN: 'SIGN_IN',
|
|
50
|
+
SIGN_UP: 'SIGN_UP',
|
|
51
|
+
IMPORTANT_BUTTON_CLICKED: 'IMPORTANT_BUTTON_CLICKED'
|
|
52
|
+
},
|
|
53
|
+
// TOKENS // (optional),
|
|
54
|
+
includeUserKeys,
|
|
55
|
+
withDeviceInfo: true, // (optional) has default value
|
|
56
|
+
withServerLocationInfo: false, // (optional) has default value
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
buildConfig(analyticsConfig)
|
|
60
|
+
|
|
61
|
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
62
|
+
<React.StrictMode>
|
|
63
|
+
<ReactMarketingProvider>
|
|
64
|
+
<App />
|
|
65
|
+
</ReactMarketingProvider>
|
|
66
|
+
</React.StrictMode>
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage with Provider
|
|
72
|
+
```js
|
|
73
|
+
import { useState, useEffect } from 'react'
|
|
74
|
+
import { ContextApi, ContextState, useMarketingApi, useMarketingState } from 'react-marketing-tools'
|
|
75
|
+
|
|
76
|
+
function App() {
|
|
77
|
+
const [count, setCount] = useState(0)
|
|
78
|
+
const {
|
|
79
|
+
analyticsPlatform,
|
|
80
|
+
eventActionPrefixList,
|
|
81
|
+
analyticsGlobalEventActionList
|
|
82
|
+
} = useMarketingState(ContextState)
|
|
83
|
+
const {
|
|
84
|
+
trackAnalyticsEvent,
|
|
85
|
+
/*
|
|
86
|
+
NOTE: If you want to see built in config items and your added items, use one of the following functions to the body of your functional component or useEffect/function
|
|
87
|
+
call it like so showMeBuildInAnalyticsPlatform() then check your console, in dev tools.
|
|
88
|
+
showMeBuildInAnalyticsPlatform,
|
|
89
|
+
showMeBuildInEventActionPrefixList,
|
|
90
|
+
showMeBuildInGlobalEventActionList,
|
|
91
|
+
*/
|
|
92
|
+
} = useMarketingApi(ContextApi)
|
|
93
|
+
|
|
94
|
+
useEffect(function appLoadPageLandingWelcome() {
|
|
95
|
+
const eventNameInfo = {
|
|
96
|
+
actionPrefix: eventActionPrefixList.JOURNEY,
|
|
97
|
+
description: 'Welcome Landing',
|
|
98
|
+
globalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
trackAnalyticsEvent({
|
|
102
|
+
data: {},
|
|
103
|
+
eventNameInfo,
|
|
104
|
+
analyticsType: analyticsPlatform.DATALAYER_PUSH,
|
|
105
|
+
dataLayerCheck: true,
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const handleButtonClick = () => {
|
|
110
|
+
setCount((count) => count + 1)
|
|
111
|
+
|
|
112
|
+
const eventNameInfo = {
|
|
113
|
+
eventName: 'count button click',
|
|
114
|
+
actionPrefix: eventActionPrefixList.INTERACTION,
|
|
115
|
+
globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
|
|
116
|
+
previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
trackAnalyticsEvent({
|
|
120
|
+
data: {
|
|
121
|
+
count,
|
|
122
|
+
firstName: 'bob',
|
|
123
|
+
lastName: 'yeah nah',
|
|
124
|
+
email: 'yeahnah@gmail.com',
|
|
125
|
+
},
|
|
126
|
+
eventNameInfo,
|
|
127
|
+
analyticsType: analyticsPlatform.DATALAYER_PUSH,
|
|
128
|
+
consoleLogData: {
|
|
129
|
+
showJourneyPropsPayload: true
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
...
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
...
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Usage without Provider
|
|
143
|
+
```js
|
|
144
|
+
import { useState, useEffect, useCallback } from 'react'
|
|
145
|
+
import { trackAnalyticsEvent, analyticsPlatform } from "react-marketing-tools";
|
|
146
|
+
|
|
147
|
+
const WelcomePage = () => {
|
|
148
|
+
useEffect(function appLoadPageLandingWelcome() {
|
|
149
|
+
const eventNameInfo = {
|
|
150
|
+
actionPrefix: eventActionPrefixList.JOURNEY,
|
|
151
|
+
description: 'Welcome Landing',
|
|
152
|
+
globalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
trackAnalyticsEvent({
|
|
156
|
+
data: {},
|
|
157
|
+
eventNameInfo,
|
|
158
|
+
analyticsType: analyticsPlatform.DATALAYER_PUSH,
|
|
159
|
+
dataLayerCheck: true,
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const handleButtonClick = () => {
|
|
164
|
+
setCount((count) => count + 1)
|
|
165
|
+
|
|
166
|
+
const eventNameInfo = {
|
|
167
|
+
eventName: 'count button click',
|
|
168
|
+
actionPrefix: eventActionPrefixList.INTERACTION,
|
|
169
|
+
globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
|
|
170
|
+
previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
trackAnalyticsEvent({
|
|
174
|
+
data: {
|
|
175
|
+
count,
|
|
176
|
+
firstName: 'bob',
|
|
177
|
+
lastName: 'yeah nah',
|
|
178
|
+
email: 'yeahnah@gmail.com',
|
|
179
|
+
},
|
|
180
|
+
eventNameInfo,
|
|
181
|
+
analyticsType: analyticsPlatform.DATALAYER_PUSH,
|
|
182
|
+
consoleLogData: {
|
|
183
|
+
showJourneyPropsPayload: true
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
...
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
...
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
```
|