react-marketing-tools 0.2.1 → 0.2.2

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 CHANGED
@@ -21,6 +21,7 @@ COMING SOON: [React Marketing Tools Demo](https://)
21
21
  import React from 'react'
22
22
  import ReactDOM from 'react-dom/client'
23
23
  import { ReactMarketingProvider, buildConfig } from 'react-marketing-tools';
24
+ import { BuildConfigOptions } from './lib/types'
24
25
  import App from './App'
25
26
 
26
27
  /*
@@ -43,7 +44,7 @@ COMING SOON: [React Marketing Tools Demo](https://)
43
44
  'lastName',
44
45
  ]
45
46
 
46
- const analyticsConfig = {
47
+ const analyticsConfig: BuildConfigOptions = {
47
48
  appName: 'my-awesome-app', // required
48
49
  appSessionCookieName: 'APP_SESSION',
49
50
  eventActionPrefix: { // this will extend the default values of eventActionPrefix
@@ -88,19 +89,20 @@ COMING SOON: [React Marketing Tools Demo](https://)
88
89
 
89
90
  ## Usage with Provider
90
91
  ```js
91
- import { useState, useEffect } from 'react'
92
- import { ContextApi, ContextState, useMarketingApi, useMarketingState } from 'react-marketing-tools'
92
+ import { useState, useEffect, useCallback, useRef } from 'react'
93
+ import { ProviderApiProps, ProviderStateProps, useMarketingApi, useMarketingState } from './lib'
94
+ import { EventNameInfo, TrackAnalyticsEventOptions } from './lib/types'
93
95
 
94
96
  function App() {
95
97
  const [count, setCount] = useState(0)
96
98
  const {
97
- appSessionCookieName,
98
99
  analyticsPlatform,
100
+ appSessionCookieName,
99
101
  eventActionPrefixList,
100
- analyticsGlobalEventActionList
101
- } = useMarketingState(ContextState)
102
+ analyticsGlobalEventActionList,
103
+ }: ProviderStateProps = useMarketingState()
102
104
  const {
103
- trackAnalyticsEvent,
105
+ trackAnalyticsEvent
104
106
  /*
105
107
  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
106
108
  call it like so showMeBuildInAnalyticsPlatform() then check your console, in dev tools.
@@ -108,70 +110,77 @@ COMING SOON: [React Marketing Tools Demo](https://)
108
110
  showMeBuildInEventActionPrefixList,
109
111
  showMeBuildInGlobalEventActionList,
110
112
  */
111
- } = useMarketingApi(ContextApi)
113
+ }: ProviderApiProps = useMarketingApi()
112
114
 
113
115
  useEffect(function appLoadPageLandingWelcome() {
114
116
  // create session cookie, useful for unauthenticated user tracking and other things
115
117
  document.cookie = `${appSessionCookieName}=${uuid()};max-age=${70};SameSite=Strict;Secure`
116
118
 
117
119
  const sendAnalyticsEvent = async () => {
118
- const eventNameInfo = {
120
+ const eventNameInfo: EventNameInfo = {
121
+ eventName: 'Welcome Landing',
119
122
  actionPrefix: eventActionPrefixList.JOURNEY,
120
- description: 'Welcome Landing',
121
123
  globalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
122
124
  }
123
125
 
124
- await trackAnalyticsEvent({
126
+ const trackingData: TrackAnalyticsEventOptions = {
125
127
  data: {},
126
128
  eventNameInfo,
127
129
  analyticsType: analyticsPlatform.DATALAYER_PUSH,
128
130
  dataLayerCheck: true,
129
- })
131
+ userDataToHashKeyArray: null,
132
+ }
133
+
134
+ await trackAnalyticsEvent(trackingData)
130
135
  }
131
136
 
132
137
  sendAnalyticsEvent()
133
- })
138
+ }, [])
134
139
 
135
- const handleButtonClick = async () => {
140
+ const handleButtonClick = useCallback(async () => {
136
141
  const countActual = count + 1
137
142
  setCount(countActual)
138
143
 
139
- const eventNameInfo = {
144
+ const eventNameInfo: EventNameInfo = {
140
145
  eventName: 'count button click',
141
146
  actionPrefix: eventActionPrefixList.INTERACTION,
142
147
  globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
143
- previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED
148
+ previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
144
149
  }
145
150
 
146
- await trackAnalyticsEvent({
151
+ const trackingData: TrackAnalyticsEventOptions = {
147
152
  data: {
148
153
  count: countActual,
149
- firstName: 'bob',
154
+ // firstName: 'bob',
150
155
  lastName: 'yeah nah',
151
156
  email: 'yeahnah@gmail.com',
152
157
  },
153
158
  eventNameInfo,
154
159
  analyticsType: analyticsPlatform.DATALAYER_PUSH,
155
160
  consoleLogData: {
156
- showJourneyPropsPayload: true
157
- }
158
- })
159
- }
161
+ showJourneyPropsPayload: true,
162
+ },
163
+ dataLayerCheck: false,
164
+ userDataToHashKeyArray: null,
165
+ }
166
+
167
+ await trackAnalyticsEvent(trackingData)
168
+ }, [count])
160
169
 
161
170
  /* Example: use GA4 directly
162
- const handleButtonClick = useCallback(async () => {
163
- const countActual = count + 1
171
+ const handleButtonClick = useCallback(async () => {
172
+ const countActual = count + 1
164
173
 
165
- setCount(countActual)
174
+ setCount(countActual)
166
175
 
167
- const eventNameInfo = {
176
+ const eventNameInfo: EventNameInfo = {
168
177
  eventName: 'count button click',
169
178
  actionPrefix: eventActionPrefixList.INTERACTION,
170
179
  globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
171
180
  previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
172
- }
181
+ }
173
182
 
174
- await trackAnalyticsEvent({
183
+ const trackingData: TrackAnalyticsEventOptions = {
175
184
  data: {
176
185
  count: countActual,
177
186
  firstName: 'bob',
@@ -184,9 +193,12 @@ COMING SOON: [React Marketing Tools Demo](https://)
184
193
  consoleLogData: {
185
194
  showJourneyPropsPayload: true,
186
195
  },
187
- })
188
- }, [count])
196
+ }
197
+
198
+ await trackAnalyticsEvent(trackingData)
199
+ }, [count])
189
200
  */
201
+
190
202
  ...
191
203
 
192
204
  return (
@@ -200,22 +212,25 @@ COMING SOON: [React Marketing Tools Demo](https://)
200
212
  ```js
201
213
  import { useState, useEffect, useCallback } from 'react'
202
214
  import { trackAnalyticsEvent, analyticsPlatform } from "react-marketing-tools";
215
+ import { EventNameInfo, TrackAnalyticsEventOptions } from './lib/types'
203
216
 
204
217
  const WelcomePage = () => {
205
218
  useEffect(function appLoadPageLandingWelcome() {
206
219
  const sendAnalyticsEvent = async () => {
207
- const eventNameInfo = {
220
+ const eventNameInfo: EventNameInfo = {
208
221
  actionPrefix: eventActionPrefixList.JOURNEY,
209
222
  description: 'Welcome Landing',
210
223
  globalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED,
211
224
  }
212
225
 
213
- trackAnalyticsEvent({
226
+ const trackingData: TrackAnalyticsEventOptions = {
214
227
  data: {},
215
228
  eventNameInfo,
216
229
  analyticsType: analyticsPlatform.DATALAYER_PUSH,
217
230
  dataLayerCheck: true,
218
- })
231
+ }
232
+
233
+ await trackAnalyticsEvent(trackingData)
219
234
  }
220
235
 
221
236
  sendAnalyticsEvent()
@@ -225,14 +240,14 @@ COMING SOON: [React Marketing Tools Demo](https://)
225
240
  const countActual = count + 1
226
241
  setCount(countActual)
227
242
 
228
- const eventNameInfo = {
243
+ const eventNameInfo: EventNameInfo = {
229
244
  eventName: 'count button click',
230
245
  actionPrefix: eventActionPrefixList.INTERACTION,
231
246
  globalAppEvent: analyticsGlobalEventActionList.AUTHENTICATED,
232
247
  previousGlobalAppEvent: analyticsGlobalEventActionList.UNAUTHENTICATED
233
248
  }
234
249
 
235
- await trackAnalyticsEvent({
250
+ const trackingData: TrackAnalyticsEventOptions = {
236
251
  data: {
237
252
  count: countActual,
238
253
  firstName: 'bob',
@@ -244,7 +259,9 @@ COMING SOON: [React Marketing Tools Demo](https://)
244
259
  consoleLogData: {
245
260
  showJourneyPropsPayload: true
246
261
  }
247
- })
262
+ }
263
+
264
+ await trackAnalyticsEvent(trackingData)
248
265
  }
249
266
  ...
250
267
 
@@ -1,3 +1,4 @@
1
+ import { TrackAnalyticsEventOptions } from './types';
1
2
  /**
2
3
  *
3
4
  * @paramType {object} options
@@ -8,21 +9,5 @@
8
9
  * @property {boolean} dataLayerCheck
9
10
  * @property {object} consoleLogData (optional) is an object with the following attributes, "showGlobalVars", "showJourneyPropsPayload", "showUserProps" if any of the values are true you will be able to see the respective payload in your console.
10
11
  */
11
- export declare type EventNameInfo = {
12
- eventName: string;
13
- description?: string;
14
- actionPrefix: string;
15
- globalAppEvent: string;
16
- previousGlobalAppEvent?: string;
17
- };
18
- export declare type AllowedTypes = string | number;
19
- export declare type TrackAnalyticsEventOptions = {
20
- data: Record<AllowedTypes, AllowedTypes>;
21
- eventNameInfo: EventNameInfo;
22
- analyticsType: string;
23
- userDataToHashKeyArray: Array<string> | null;
24
- dataLayerCheck: boolean;
25
- consoleLogData?: object;
26
- };
27
12
  declare const trackAnalyticsEvent: (options: TrackAnalyticsEventOptions) => Promise<void>;
28
13
  export { trackAnalyticsEvent };
@@ -1,5 +1,5 @@
1
1
  import DeviceDetector from 'device-detector-js';
2
- import { AllowedTypes, EventNameInfo } from './analyticsEventService';
2
+ import { AllowedTypes, EventNameInfo } from './types';
3
3
  /**
4
4
  *
5
5
  * @param {object} user the structure of this data is dictated by you, aka your API or DB.
@@ -1,3 +1,34 @@
1
+ export declare type Event = {
2
+ name: string;
3
+ params: Record<AllowedTypes, AllowedTypes>;
4
+ };
5
+ export declare type GooglePayload = {
6
+ non_personalized_ads: boolean;
7
+ client_id: string;
8
+ user_id: string;
9
+ user_properties: {
10
+ user_id: string;
11
+ user_type: string;
12
+ client_id: string;
13
+ };
14
+ events: Event[];
15
+ };
16
+ export declare type EventNameInfo = {
17
+ eventName: string;
18
+ description?: string;
19
+ actionPrefix: string;
20
+ globalAppEvent: string;
21
+ previousGlobalAppEvent?: string;
22
+ };
23
+ export declare type AllowedTypes = string | number;
24
+ export declare type TrackAnalyticsEventOptions = {
25
+ data: Record<AllowedTypes, AllowedTypes>;
26
+ eventNameInfo: EventNameInfo;
27
+ analyticsType: string;
28
+ userDataToHashKeyArray: Array<string> | null;
29
+ dataLayerCheck: boolean;
30
+ consoleLogData?: object;
31
+ };
1
32
  export declare type GlobalVars = {
2
33
  app: string;
3
34
  device_category?: string | undefined;
@@ -1,37 +1,10 @@
1
- export declare type Platform = Record<string, string>;
1
+ import { BuildConfigOptions, Config, Platform } from './types';
2
2
  export declare const analyticsPlatform: Platform;
3
3
  export declare const showMeBuildInAnalyticsPlatform: () => void;
4
4
  export declare const analyticsEventActionPrefixList: Record<string, string>;
5
5
  export declare const showMeBuildInEventActionPrefixList: () => void;
6
6
  export declare const analyticsGlobalEventActionList: Record<string, string>;
7
7
  export declare const showMeBuildInGlobalEventActionList: () => void;
8
- declare type Tokens = {
9
- IP_INFO_TOKEN?: string;
10
- GA4_PUBLIC_API_SECRET: string;
11
- GA4_PUBLIC_MEASUREMENT_ID: string;
12
- };
13
- export declare type Config = {
14
- TOKENS?: Tokens;
15
- appName: string;
16
- appSessionCookieName: string;
17
- withDeviceInfo?: boolean;
18
- includeUserKeys: Array<string>;
19
- showMissingUserAttributesInConsole: boolean | undefined;
20
- withServerLocationInfo: boolean | undefined;
21
- eventActionPrefixList: Record<string, string>;
22
- analyticsGlobalEventActionList: Record<string, string>;
23
- };
24
8
  export declare let config: Config;
25
- export declare type BuildConfigOptions = {
26
- appName: string;
27
- appSessionCookieName: string;
28
- eventActionPrefix: Record<string, string>;
29
- globalEventActionList: Record<string, string>;
30
- includeUserKeys: Array<string>;
31
- showMissingUserAttributesInConsole: boolean | undefined;
32
- TOKENS?: Tokens;
33
- withDeviceInfo: boolean | undefined;
34
- withServerLocationInfo: boolean | undefined;
35
- };
36
9
  declare const buildConfig: (options: BuildConfigOptions) => void;
37
10
  export { buildConfig };
@@ -0,0 +1,28 @@
1
+ export declare type Platform = Record<string, string>;
2
+ export declare type Tokens = {
3
+ IP_INFO_TOKEN?: string;
4
+ GA4_PUBLIC_API_SECRET?: string;
5
+ GA4_PUBLIC_MEASUREMENT_ID?: string;
6
+ };
7
+ export declare type Config = {
8
+ TOKENS?: Tokens;
9
+ appName: string;
10
+ appSessionCookieName: string;
11
+ withDeviceInfo?: boolean;
12
+ includeUserKeys: Array<string>;
13
+ showMissingUserAttributesInConsole: boolean | undefined;
14
+ withServerLocationInfo: boolean | undefined;
15
+ eventActionPrefixList: Record<string, string>;
16
+ analyticsGlobalEventActionList: Record<string, string>;
17
+ };
18
+ export declare type BuildConfigOptions = {
19
+ appName: string;
20
+ appSessionCookieName: string;
21
+ eventActionPrefix: Record<string, string>;
22
+ globalEventActionList: Record<string, string>;
23
+ includeUserKeys: Array<string>;
24
+ showMissingUserAttributesInConsole: boolean | undefined;
25
+ TOKENS?: Tokens;
26
+ withDeviceInfo: boolean | undefined;
27
+ withServerLocationInfo: boolean | undefined;
28
+ };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { Platform } from './buildConfig';
3
- import { TrackAnalyticsEventOptions } from './analytics/analyticsEventService';
2
+ import { Platform, TrackAnalyticsEventOptions } from './types';
4
3
  export { buildConfig, analyticsPlatform } from './buildConfig';
5
4
  export { trackAnalyticsEvent } from './analytics/analyticsEventService';
6
5
  export declare type ProviderStateProps = {
@@ -1,23 +1,3 @@
1
- export declare type ServerLocationData = {
2
- SERVER_CITY: string;
3
- SERVER_COUNTRY: string;
4
- SERVER_HOSTNAME: string;
5
- SERVER_IP: string;
6
- SERVER_LOCATION: string;
7
- SERVER_POSTAL: string;
8
- SERVER_REGION: string;
9
- SERVER_TIMEZONE: string;
10
- };
1
+ import { IpInfo, ServerLocationData } from './types';
11
2
  export declare const buildServerLocationData: (withServerLocationInfo: boolean | undefined) => Promise<ServerLocationData | undefined>;
12
- export declare type IpInfo = {
13
- city: string;
14
- country: string;
15
- SERVER_HOSTNAME: string;
16
- hostname: string;
17
- ip: string;
18
- loc: string;
19
- postal: string;
20
- region: string;
21
- timezone: string;
22
- };
23
3
  export declare const getIpInfo: (IP_INFO_TOKEN: string) => Promise<IpInfo>;
@@ -0,0 +1,21 @@
1
+ export declare type ServerLocationData = {
2
+ SERVER_CITY: string;
3
+ SERVER_COUNTRY: string;
4
+ SERVER_HOSTNAME: string;
5
+ SERVER_IP: string;
6
+ SERVER_LOCATION: string;
7
+ SERVER_POSTAL: string;
8
+ SERVER_REGION: string;
9
+ SERVER_TIMEZONE: string;
10
+ };
11
+ export declare type IpInfo = {
12
+ city: string;
13
+ country: string;
14
+ SERVER_HOSTNAME: string;
15
+ hostname: string;
16
+ ip: string;
17
+ loc: string;
18
+ postal: string;
19
+ region: string;
20
+ timezone: string;
21
+ };
@@ -0,0 +1,3 @@
1
+ export * from './analytics/types';
2
+ export * from './buildConfig/types';
3
+ export * from './ipInfo/types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-marketing-tools",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "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
  "license": "MIT",
6
6
  "author": "bronz3beard <exempli.gratia.webdesign@gmail.com> (https://www.heyrory.com/)",