@cuemath/web-utils 0.0.2-beta.2 → 0.0.2-beta.4
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 +5 -5
- package/src/growth-source/index.ts +52 -33
- package/src/growth-source/types.ts +9 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuemath/web-utils",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.2-beta.4",
|
|
4
|
+
"description": "Shared web utils package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "tsc --noEmit && eslint 'src/**/*.{js,jsx,ts,tsx,json}'",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/cuemath/
|
|
15
|
+
"url": "git+https://github.com/cuemath/web-utils.git"
|
|
16
16
|
},
|
|
17
17
|
"bugs": {
|
|
18
|
-
"url": "https://github.com/cuemath/
|
|
18
|
+
"url": "https://github.com/cuemath/web-utils/issues"
|
|
19
19
|
},
|
|
20
|
-
"homepage": "https://github.com/cuemath/
|
|
20
|
+
"homepage": "https://github.com/cuemath/web-utils#readme",
|
|
21
21
|
"author": "santosh k <santosh.k@cuemath.com>",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"devDependencies": {
|
|
@@ -18,17 +18,23 @@ const UTM_PARAMS: UTMParamsKeys[] = [
|
|
|
18
18
|
'utm_term',
|
|
19
19
|
];
|
|
20
20
|
|
|
21
|
-
export const readSourceCookie = () => {
|
|
21
|
+
export const readSourceCookie = (): SourceDetails => {
|
|
22
22
|
const sourceDetails = getCookie(SOURCE_DETAILS_COOKIE);
|
|
23
23
|
|
|
24
|
-
return sourceDetails
|
|
24
|
+
return sourceDetails ? JSON.parse(decodeURIComponent(sourceDetails)) : undefined;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const writeSourceCookie = (sourceDetails: SourceDetails) => {
|
|
27
|
+
const writeSourceCookie = (sourceDetails: SourceDetails): void => {
|
|
28
28
|
createCookie(SOURCE_DETAILS_COOKIE, JSON.stringify(sourceDetails), 365, true);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
export const isSourcePresent = (): boolean => {
|
|
32
|
+
return !!getCookie(SOURCE_DETAILS_COOKIE);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const updateSourceCookie = (sourceDetail: Partial<SourceDetails>): void => {
|
|
36
|
+
if (!isSourcePresent) return;
|
|
37
|
+
|
|
32
38
|
const sourceDetails: SourceDetails = readSourceCookie();
|
|
33
39
|
const updatedDetails: SourceDetails = {
|
|
34
40
|
...sourceDetails,
|
|
@@ -38,32 +44,35 @@ const updateSourceCookie = (sourceDetail: Partial<SourceDetails>) => {
|
|
|
38
44
|
writeSourceCookie(updatedDetails);
|
|
39
45
|
};
|
|
40
46
|
|
|
41
|
-
const getRevenueChannel = (platform: Platform, utmParams?: UTMParams) => {
|
|
42
|
-
let revenueChannel: RevenueChannel = '
|
|
47
|
+
const getRevenueChannel = (platform: Platform, utmParams?: UTMParams): RevenueChannel => {
|
|
48
|
+
let revenueChannel: RevenueChannel = 'unknown';
|
|
49
|
+
|
|
50
|
+
// set defaults for WEBSITE and ASTRO
|
|
51
|
+
if (platform === 'website') {
|
|
52
|
+
revenueChannel = 'organic';
|
|
53
|
+
} else if (platform === 'astro') {
|
|
54
|
+
revenueChannel = 'performance';
|
|
55
|
+
}
|
|
43
56
|
|
|
44
|
-
if (
|
|
57
|
+
if (utmParams) {
|
|
45
58
|
const { utm_source: utmSource = '' } = utmParams;
|
|
46
59
|
|
|
47
60
|
switch (true) {
|
|
48
61
|
case /^affiliate-/.test(utmSource):
|
|
49
|
-
revenueChannel = '
|
|
62
|
+
revenueChannel = 'affiliate';
|
|
50
63
|
break;
|
|
51
64
|
case /^offline-/.test(utmSource):
|
|
52
|
-
revenueChannel = '
|
|
65
|
+
revenueChannel = 'offline';
|
|
53
66
|
break;
|
|
54
67
|
case /^referral-/.test(utmSource):
|
|
55
|
-
revenueChannel = '
|
|
68
|
+
revenueChannel = 'referral';
|
|
56
69
|
break;
|
|
57
70
|
case /^performance-/.test(utmSource):
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
revenueChannel = 'performance';
|
|
72
|
+
break;
|
|
60
73
|
}
|
|
61
74
|
}
|
|
62
75
|
|
|
63
|
-
if (platform === 'WEBSITE') {
|
|
64
|
-
revenueChannel = 'ORGANIC';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
76
|
return revenueChannel;
|
|
68
77
|
};
|
|
69
78
|
|
|
@@ -73,23 +82,23 @@ const getRevenueChannel = (platform: Platform, utmParams?: UTMParams) => {
|
|
|
73
82
|
if Platform = APP, decide logic
|
|
74
83
|
if Platform = chatbot, decide based on chatbot experiment key
|
|
75
84
|
*/
|
|
76
|
-
const getFlow = (platform: Platform, experiments?: Experiments) => {
|
|
77
|
-
let flow: SignupFlow = '
|
|
85
|
+
const getFlow = (platform: Platform, experiments?: Experiments): SignupFlow => {
|
|
86
|
+
let flow: SignupFlow = 'regular';
|
|
78
87
|
|
|
79
|
-
if (platform === '
|
|
88
|
+
if (platform === 'website') {
|
|
80
89
|
if (experiments) {
|
|
81
90
|
const ecnaExp = Object.keys(experiments).find(
|
|
82
91
|
experiment => experiment.indexOf('ecna') !== -1,
|
|
83
92
|
);
|
|
84
93
|
|
|
85
|
-
flow = ecnaExp && experiments[ecnaExp] === 'b' ? '
|
|
94
|
+
flow = ecnaExp && experiments[ecnaExp] === 'b' ? 'e-cna' : 'regular';
|
|
86
95
|
}
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
return flow;
|
|
90
99
|
};
|
|
91
100
|
|
|
92
|
-
const getUTMParams = () => {
|
|
101
|
+
const getUTMParams = (): UTMParams | undefined => {
|
|
93
102
|
if (typeof window === undefined) return;
|
|
94
103
|
|
|
95
104
|
const search = new URLSearchParams(window.location.search);
|
|
@@ -106,7 +115,7 @@ const getUTMParams = () => {
|
|
|
106
115
|
return utmParams;
|
|
107
116
|
};
|
|
108
117
|
|
|
109
|
-
const getFirstPage = () => {
|
|
118
|
+
const getFirstPage = (): string => {
|
|
110
119
|
if (typeof window === undefined) return '';
|
|
111
120
|
|
|
112
121
|
return window.location.pathname;
|
|
@@ -118,7 +127,7 @@ const getFirstPage = () => {
|
|
|
118
127
|
organic-<channel>
|
|
119
128
|
offline-<channel>
|
|
120
129
|
*/
|
|
121
|
-
const getChannel = (utmParams: UTMParams | undefined) => {
|
|
130
|
+
const getChannel = (utmParams: UTMParams | undefined): string => {
|
|
122
131
|
// TODO: UTM source patter for FB, GOOGLE...
|
|
123
132
|
if (!utmParams) return '';
|
|
124
133
|
|
|
@@ -133,27 +142,37 @@ const getChannel = (utmParams: UTMParams | undefined) => {
|
|
|
133
142
|
export const initSourceDetails = async ({
|
|
134
143
|
platform,
|
|
135
144
|
experiments,
|
|
136
|
-
utmParams,
|
|
137
145
|
flow,
|
|
138
146
|
affiliateChannel,
|
|
139
147
|
offlineChannel,
|
|
140
148
|
organicChannel,
|
|
141
149
|
performanceChannel,
|
|
142
150
|
revenueChannel,
|
|
143
|
-
}: SourceDetails) => {
|
|
144
|
-
if (!
|
|
151
|
+
}: SourceDetails): Promise<void> => {
|
|
152
|
+
if (!isSourcePresent()) {
|
|
153
|
+
const utmParams = getUTMParams();
|
|
145
154
|
const leadChannel = getChannel(utmParams);
|
|
146
155
|
|
|
156
|
+
revenueChannel = revenueChannel || getRevenueChannel(platform, utmParams);
|
|
157
|
+
affiliateChannel =
|
|
158
|
+
revenueChannel === 'affiliate' ? affiliateChannel || leadChannel : undefined;
|
|
159
|
+
offlineChannel =
|
|
160
|
+
revenueChannel === 'offline' ? offlineChannel || leadChannel : undefined;
|
|
161
|
+
organicChannel =
|
|
162
|
+
revenueChannel === 'organic' ? organicChannel || leadChannel : undefined;
|
|
163
|
+
performanceChannel =
|
|
164
|
+
revenueChannel === 'performance' ? performanceChannel || leadChannel : undefined;
|
|
165
|
+
|
|
147
166
|
const sourceDetails: SourceDetails = {
|
|
148
167
|
platform,
|
|
149
168
|
experiments,
|
|
150
169
|
utmParams: getUTMParams(),
|
|
151
170
|
flow: flow || getFlow(platform, experiments),
|
|
152
|
-
affiliateChannel
|
|
153
|
-
offlineChannel
|
|
154
|
-
organicChannel
|
|
155
|
-
performanceChannel
|
|
156
|
-
revenueChannel: revenueChannel
|
|
171
|
+
affiliateChannel,
|
|
172
|
+
offlineChannel,
|
|
173
|
+
organicChannel,
|
|
174
|
+
performanceChannel,
|
|
175
|
+
revenueChannel: revenueChannel,
|
|
157
176
|
firstPage: getFirstPage(),
|
|
158
177
|
};
|
|
159
178
|
|
|
@@ -162,11 +181,11 @@ export const initSourceDetails = async ({
|
|
|
162
181
|
};
|
|
163
182
|
|
|
164
183
|
// Last Page which user visited signup before
|
|
165
|
-
export const setLastPage = async (pagePath: string) => {
|
|
184
|
+
export const setLastPage = async (pagePath: string): Promise<void> => {
|
|
166
185
|
updateSourceCookie({ lastPage: pagePath });
|
|
167
186
|
};
|
|
168
187
|
|
|
169
188
|
// set Entry point where user clicked to Signup
|
|
170
|
-
export const setFlowEntryPoint = async (flowEntry: string) => {
|
|
189
|
+
export const setFlowEntryPoint = async (flowEntry: string): Promise<void> => {
|
|
171
190
|
updateSourceCookie({ flowEntry });
|
|
172
191
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export type Platform = '
|
|
1
|
+
export type Platform = 'website' | 'app' | 'astro' | 'leap-teacher' | 'leap-admin';
|
|
2
2
|
export type RevenueChannel =
|
|
3
|
-
| '
|
|
4
|
-
| '
|
|
5
|
-
| '
|
|
6
|
-
| '
|
|
7
|
-
| '
|
|
8
|
-
| '
|
|
9
|
-
export type SignupFlow = '
|
|
3
|
+
| 'organic'
|
|
4
|
+
| 'performance'
|
|
5
|
+
| 'affiliate'
|
|
6
|
+
| 'offline'
|
|
7
|
+
| 'referral'
|
|
8
|
+
| 'unknown';
|
|
9
|
+
export type SignupFlow = 'regular' | 'e-cna' | 'e-sales';
|
|
10
10
|
export type Experiments = Record<string, unknown>;
|
|
11
11
|
export type UTMParams = {
|
|
12
12
|
utm_source?: string;
|
|
@@ -24,7 +24,7 @@ export type SourceDetails = {
|
|
|
24
24
|
utmParams?: UTMParams;
|
|
25
25
|
affiliateChannel?: string;
|
|
26
26
|
offlineChannel?: string;
|
|
27
|
-
performanceChannel
|
|
27
|
+
performanceChannel?: string;
|
|
28
28
|
revenueChannel: RevenueChannel;
|
|
29
29
|
organicChannel?: string;
|
|
30
30
|
flowEntry?: string;
|