@cuemath/web-utils 1.0.0-beta.14 → 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/.husky/pre-commit +0 -1
- package/dist/cookie/index.d.ts +1 -1
- package/dist/cookie/index.js +2 -3
- package/dist/cookie/index.js.map +1 -1
- package/dist/growth-source/index.d.ts +6 -0
- package/dist/growth-source/index.js +151 -0
- package/dist/growth-source/index.js.map +1 -0
- package/dist/growth-source/types.d.ts +25 -0
- package/dist/growth-source/types.js +3 -0
- package/dist/growth-source/types.js.map +1 -0
- package/dist/index.d.ts +1 -6
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -7
- package/src/cookie/index.ts +10 -4
- package/src/growth-source/index.ts +191 -0
- package/src/growth-source/types.ts +33 -0
- package/src/index.ts +1 -6
- package/.eslintignore +0 -2
- package/.huskyrc +0 -5
- package/.lintstagedrc.yml +0 -5
- package/dist/constants/country/index.d.ts +0 -2
- package/dist/constants/country/index.js +0 -7
- package/dist/constants/country/index.js.map +0 -1
- package/dist/constants/country/iso-country-code.d.ts +0 -248
- package/dist/constants/country/iso-country-code.js +0 -252
- package/dist/constants/country/iso-country-code.js.map +0 -1
- package/dist/constants/date-time/index.d.ts +0 -17
- package/dist/constants/date-time/index.js +0 -42
- package/dist/constants/date-time/index.js.map +0 -1
- package/dist/constants/date-time/international-timezones.d.ts +0 -7
- package/dist/constants/date-time/international-timezones.js +0 -155
- package/dist/constants/date-time/international-timezones.js.map +0 -1
- package/dist/constants/e-cna/index.d.ts +0 -41
- package/dist/constants/e-cna/index.js +0 -45
- package/dist/constants/e-cna/index.js.map +0 -1
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.js +0 -19
- package/dist/constants/index.js.map +0 -1
- package/dist/country/index.d.ts +0 -1
- package/dist/country/index.js +0 -13
- package/dist/country/index.js.map +0 -1
- package/dist/date-time-helper/e-cna.d.ts +0 -32
- package/dist/date-time-helper/e-cna.js +0 -153
- package/dist/date-time-helper/e-cna.js.map +0 -1
- package/dist/date-time-helper/index.d.ts +0 -54
- package/dist/date-time-helper/index.js +0 -290
- package/dist/date-time-helper/index.js.map +0 -1
- package/dist/e-cna/flow/aggregator.d.ts +0 -473
- package/dist/e-cna/flow/aggregator.js +0 -17
- package/dist/e-cna/flow/aggregator.js.map +0 -1
- package/dist/e-cna/flow/index.d.ts +0 -1
- package/dist/e-cna/flow/index.js +0 -18
- package/dist/e-cna/flow/index.js.map +0 -1
- package/dist/e-cna/flow/variants/default.d.ts +0 -734
- package/dist/e-cna/flow/variants/default.js +0 -95
- package/dist/e-cna/flow/variants/default.js.map +0 -1
- package/dist/e-cna/flow/variants/index.d.ts +0 -1
- package/dist/e-cna/flow/variants/index.js +0 -18
- package/dist/e-cna/flow/variants/index.js.map +0 -1
- package/dist/e-cna/index.d.ts +0 -43
- package/dist/e-cna/index.js +0 -221
- package/dist/e-cna/index.js.map +0 -1
- package/dist/e-cna/slides/child_hobbies/index.d.ts +0 -1
- package/dist/e-cna/slides/child_hobbies/index.js +0 -18
- package/dist/e-cna/slides/child_hobbies/index.js.map +0 -1
- package/dist/e-cna/slides/child_hobbies/variants.d.ts +0 -22
- package/dist/e-cna/slides/child_hobbies/variants.js +0 -26
- package/dist/e-cna/slides/child_hobbies/variants.js.map +0 -1
- package/dist/e-cna/slides/child_info/index.d.ts +0 -1
- package/dist/e-cna/slides/child_info/index.js +0 -18
- package/dist/e-cna/slides/child_info/index.js.map +0 -1
- package/dist/e-cna/slides/child_info/variants.d.ts +0 -17
- package/dist/e-cna/slides/child_info/variants.js +0 -22
- package/dist/e-cna/slides/child_info/variants.js.map +0 -1
- package/dist/e-cna/slides/child_personality/index.d.ts +0 -1
- package/dist/e-cna/slides/child_personality/index.js +0 -18
- package/dist/e-cna/slides/child_personality/index.js.map +0 -1
- package/dist/e-cna/slides/child_personality/variants.d.ts +0 -12
- package/dist/e-cna/slides/child_personality/variants.js +0 -16
- package/dist/e-cna/slides/child_personality/variants.js.map +0 -1
- package/dist/e-cna/slides/curriculum/index.d.ts +0 -1
- package/dist/e-cna/slides/curriculum/index.js +0 -18
- package/dist/e-cna/slides/curriculum/index.js.map +0 -1
- package/dist/e-cna/slides/curriculum/variants.d.ts +0 -12
- package/dist/e-cna/slides/curriculum/variants.js +0 -17
- package/dist/e-cna/slides/curriculum/variants.js.map +0 -1
- package/dist/e-cna/slides/grade/index.d.ts +0 -1
- package/dist/e-cna/slides/grade/index.js +0 -18
- package/dist/e-cna/slides/grade/index.js.map +0 -1
- package/dist/e-cna/slides/grade/variants.d.ts +0 -14
- package/dist/e-cna/slides/grade/variants.js +0 -31
- package/dist/e-cna/slides/grade/variants.js.map +0 -1
- package/dist/e-cna/slides/index.d.ts +0 -19
- package/dist/e-cna/slides/index.js +0 -36
- package/dist/e-cna/slides/index.js.map +0 -1
- package/dist/e-cna/slides/intro/index.d.ts +0 -1
- package/dist/e-cna/slides/intro/index.js +0 -18
- package/dist/e-cna/slides/intro/index.js.map +0 -1
- package/dist/e-cna/slides/intro/variants.d.ts +0 -7
- package/dist/e-cna/slides/intro/variants.js +0 -11
- package/dist/e-cna/slides/intro/variants.js.map +0 -1
- package/dist/e-cna/slides/key_need_l1/index.d.ts +0 -1
- package/dist/e-cna/slides/key_need_l1/index.js +0 -18
- package/dist/e-cna/slides/key_need_l1/index.js.map +0 -1
- package/dist/e-cna/slides/key_need_l1/variants.d.ts +0 -26
- package/dist/e-cna/slides/key_need_l1/variants.js +0 -57
- package/dist/e-cna/slides/key_need_l1/variants.js.map +0 -1
- package/dist/e-cna/slides/key_need_l2/index.d.ts +0 -1
- package/dist/e-cna/slides/key_need_l2/index.js +0 -18
- package/dist/e-cna/slides/key_need_l2/index.js.map +0 -1
- package/dist/e-cna/slides/key_need_l2/variants.d.ts +0 -67
- package/dist/e-cna/slides/key_need_l2/variants.js +0 -139
- package/dist/e-cna/slides/key_need_l2/variants.js.map +0 -1
- package/dist/e-cna/slides/key_need_l3/index.d.ts +0 -1
- package/dist/e-cna/slides/key_need_l3/index.js +0 -18
- package/dist/e-cna/slides/key_need_l3/index.js.map +0 -1
- package/dist/e-cna/slides/key_need_l3/variants.d.ts +0 -11
- package/dist/e-cna/slides/key_need_l3/variants.js +0 -15
- package/dist/e-cna/slides/key_need_l3/variants.js.map +0 -1
- package/dist/e-cna/slides/math-perception/index.d.ts +0 -1
- package/dist/e-cna/slides/math-perception/index.js +0 -18
- package/dist/e-cna/slides/math-perception/index.js.map +0 -1
- package/dist/e-cna/slides/math-perception/variants.d.ts +0 -15
- package/dist/e-cna/slides/math-perception/variants.js +0 -32
- package/dist/e-cna/slides/math-perception/variants.js.map +0 -1
- package/dist/e-cna/slides/other_curriculum/index.d.ts +0 -1
- package/dist/e-cna/slides/other_curriculum/index.js +0 -18
- package/dist/e-cna/slides/other_curriculum/index.js.map +0 -1
- package/dist/e-cna/slides/other_curriculum/variants.d.ts +0 -12
- package/dist/e-cna/slides/other_curriculum/variants.js +0 -17
- package/dist/e-cna/slides/other_curriculum/variants.js.map +0 -1
- package/dist/e-cna/slides/school_performance_5_12/index.d.ts +0 -1
- package/dist/e-cna/slides/school_performance_5_12/index.js +0 -18
- package/dist/e-cna/slides/school_performance_5_12/index.js.map +0 -1
- package/dist/e-cna/slides/school_performance_5_12/variants.d.ts +0 -15
- package/dist/e-cna/slides/school_performance_5_12/variants.js +0 -26
- package/dist/e-cna/slides/school_performance_5_12/variants.js.map +0 -1
- package/dist/e-cna/slides/school_performance_kg_4/index.d.ts +0 -1
- package/dist/e-cna/slides/school_performance_kg_4/index.js +0 -18
- package/dist/e-cna/slides/school_performance_kg_4/index.js.map +0 -1
- package/dist/e-cna/slides/school_performance_kg_4/variants.d.ts +0 -14
- package/dist/e-cna/slides/school_performance_kg_4/variants.js +0 -28
- package/dist/e-cna/slides/school_performance_kg_4/variants.js.map +0 -1
- package/dist/e-cna/slides/secondary_needs/index.d.ts +0 -1
- package/dist/e-cna/slides/secondary_needs/index.js +0 -18
- package/dist/e-cna/slides/secondary_needs/index.js.map +0 -1
- package/dist/e-cna/slides/secondary_needs/variants.d.ts +0 -14
- package/dist/e-cna/slides/secondary_needs/variants.js +0 -28
- package/dist/e-cna/slides/secondary_needs/variants.js.map +0 -1
- package/dist/e-cna/slides/signup/index.d.ts +0 -1
- package/dist/e-cna/slides/signup/index.js +0 -18
- package/dist/e-cna/slides/signup/index.js.map +0 -1
- package/dist/e-cna/slides/signup/variants.d.ts +0 -7
- package/dist/e-cna/slides/signup/variants.js +0 -11
- package/dist/e-cna/slides/signup/variants.js.map +0 -1
- package/dist/e-cna/slides/signup_refer/index.d.ts +0 -1
- package/dist/e-cna/slides/signup_refer/index.js +0 -18
- package/dist/e-cna/slides/signup_refer/index.js.map +0 -1
- package/dist/e-cna/slides/signup_refer/variants.d.ts +0 -12
- package/dist/e-cna/slides/signup_refer/variants.js +0 -20
- package/dist/e-cna/slides/signup_refer/variants.js.map +0 -1
- package/dist/e-cna/slides/slot_pick/index.d.ts +0 -1
- package/dist/e-cna/slides/slot_pick/index.js +0 -18
- package/dist/e-cna/slides/slot_pick/index.js.map +0 -1
- package/dist/e-cna/slides/slot_pick/variants.d.ts +0 -12
- package/dist/e-cna/slides/slot_pick/variants.js +0 -16
- package/dist/e-cna/slides/slot_pick/variants.js.map +0 -1
- package/dist/e-cna/slides/teacher_intro/index.d.ts +0 -1
- package/dist/e-cna/slides/teacher_intro/index.js +0 -18
- package/dist/e-cna/slides/teacher_intro/index.js.map +0 -1
- package/dist/e-cna/slides/teacher_intro/variants.d.ts +0 -78
- package/dist/e-cna/slides/teacher_intro/variants.js +0 -116
- package/dist/e-cna/slides/teacher_intro/variants.js.map +0 -1
- package/dist/e-cna/utils/index.d.ts +0 -4
- package/dist/e-cna/utils/index.js +0 -28
- package/dist/e-cna/utils/index.js.map +0 -1
- package/dist/local-storage/index.d.ts +0 -13
- package/dist/local-storage/index.js +0 -172
- package/dist/local-storage/index.js.map +0 -1
- package/dist/object/index.d.ts +0 -6
- package/dist/object/index.js +0 -24
- package/dist/object/index.js.map +0 -1
- package/src/constants/country/index.ts +0 -2
- package/src/constants/country/iso-country-code.ts +0 -248
- package/src/constants/date-time/index.ts +0 -43
- package/src/constants/date-time/international-timezones.ts +0 -157
- package/src/constants/e-cna/index.ts +0 -55
- package/src/constants/index.ts +0 -2
- package/src/country/index.ts +0 -9
- package/src/date-time-helper/e-cna.ts +0 -205
- package/src/date-time-helper/index.ts +0 -365
- package/src/e-cna/flow/aggregator.ts +0 -12
- package/src/e-cna/flow/index.ts +0 -1
- package/src/e-cna/flow/variants/default.ts +0 -113
- package/src/e-cna/flow/variants/index.ts +0 -1
- package/src/e-cna/index.ts +0 -249
- package/src/e-cna/slides/child_hobbies/index.ts +0 -1
- package/src/e-cna/slides/child_hobbies/variants.ts +0 -24
- package/src/e-cna/slides/child_info/index.ts +0 -1
- package/src/e-cna/slides/child_info/variants.ts +0 -18
- package/src/e-cna/slides/child_personality/index.ts +0 -1
- package/src/e-cna/slides/child_personality/variants.ts +0 -12
- package/src/e-cna/slides/curriculum/index.ts +0 -1
- package/src/e-cna/slides/curriculum/variants.ts +0 -14
- package/src/e-cna/slides/grade/index.ts +0 -1
- package/src/e-cna/slides/grade/variants.ts +0 -29
- package/src/e-cna/slides/index.ts +0 -19
- package/src/e-cna/slides/intro/index.ts +0 -1
- package/src/e-cna/slides/intro/variants.ts +0 -7
- package/src/e-cna/slides/key_need_l1/index.ts +0 -1
- package/src/e-cna/slides/key_need_l1/variants.ts +0 -57
- package/src/e-cna/slides/key_need_l2/index.ts +0 -1
- package/src/e-cna/slides/key_need_l2/variants.ts +0 -143
- package/src/e-cna/slides/key_need_l3/index.ts +0 -1
- package/src/e-cna/slides/key_need_l3/variants.ts +0 -13
- package/src/e-cna/slides/math-perception/index.ts +0 -1
- package/src/e-cna/slides/math-perception/variants.ts +0 -30
- package/src/e-cna/slides/other_curriculum/index.ts +0 -1
- package/src/e-cna/slides/other_curriculum/variants.ts +0 -14
- package/src/e-cna/slides/school_performance_5_12/index.ts +0 -1
- package/src/e-cna/slides/school_performance_5_12/variants.ts +0 -23
- package/src/e-cna/slides/school_performance_kg_4/index.ts +0 -1
- package/src/e-cna/slides/school_performance_kg_4/variants.ts +0 -25
- package/src/e-cna/slides/secondary_needs/index.ts +0 -1
- package/src/e-cna/slides/secondary_needs/variants.ts +0 -26
- package/src/e-cna/slides/signup/index.ts +0 -1
- package/src/e-cna/slides/signup/variants.ts +0 -7
- package/src/e-cna/slides/signup_refer/index.ts +0 -1
- package/src/e-cna/slides/signup_refer/variants.ts +0 -16
- package/src/e-cna/slides/slot_pick/index.ts +0 -1
- package/src/e-cna/slides/slot_pick/variants.ts +0 -12
- package/src/e-cna/slides/teacher_intro/index.ts +0 -1
- package/src/e-cna/slides/teacher_intro/variants.ts +0 -114
- package/src/e-cna/utils/index.ts +0 -32
- package/src/local-storage/index.ts +0 -186
- package/src/object/index.ts +0 -26
package/.husky/pre-commit
CHANGED
package/dist/cookie/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const getCookie: (name: string, cookie?: string) => string;
|
|
2
2
|
export declare function removeCookie(name: string): void;
|
|
3
|
-
export declare function createCookie(name: string, value: string, days: number): void;
|
|
3
|
+
export declare function createCookie(name: string, value: string, days: number, subdomain: boolean): void;
|
|
4
4
|
export declare function createCookieWithMidnightExp(name: string, value: string): void;
|
package/dist/cookie/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCookieWithMidnightExp = exports.createCookie = exports.removeCookie = exports.getCookie = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
4
|
const getCookie = (name, cookie = document.cookie) => {
|
|
6
5
|
if (!cookie) {
|
|
7
6
|
return '';
|
|
@@ -26,14 +25,14 @@ function removeCookie(name) {
|
|
|
26
25
|
document.cookie = `${name}=; expires=${date.toUTCString()}; path=/`;
|
|
27
26
|
}
|
|
28
27
|
exports.removeCookie = removeCookie;
|
|
29
|
-
function createCookie(name, value, days) {
|
|
28
|
+
function createCookie(name, value, days, subdomain) {
|
|
30
29
|
let expires = '';
|
|
31
30
|
if (days) {
|
|
32
31
|
const date = new Date();
|
|
33
32
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
34
33
|
expires = `; expires=${date.toUTCString()}`;
|
|
35
34
|
}
|
|
36
|
-
document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path
|
|
35
|
+
document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=/${subdomain ? '; domain=cuemath.com' : ''}`;
|
|
37
36
|
}
|
|
38
37
|
exports.createCookie = createCookie;
|
|
39
38
|
function createCookieWithMidnightExp(name, value) {
|
package/dist/cookie/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cookie/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cookie/index.ts"],"names":[],"mappings":";;;AAAO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,SAAiB,QAAQ,CAAC,MAAM,EAAU,EAAE;IAClF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QAC1C,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;YACd,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAE3C,IAAI,GAAG,KAAK,IAAI,EAAE;gBAChB,OAAO,KAAK,CAAC;aACd;SACF;K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,GAAG,GAAG,IAAI,IAAI,KAAK,GAAG,OAAO,UAAU,CAAC;AACzD,CAAC;AAPD,kEAOC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceDetails } from './types';
|
|
2
|
+
export declare const readSourceCookie: () => SourceDetails;
|
|
3
|
+
export declare const isSourcePresent: () => boolean;
|
|
4
|
+
export declare const initSourceDetails: ({ platform, experiments, flow, affiliateChannel, offlineChannel, organicChannel, performanceChannel, revenueChannel, }: SourceDetails) => Promise<void>;
|
|
5
|
+
export declare const setLastPage: (pagePath: string) => Promise<void>;
|
|
6
|
+
export declare const setFlowEntryPoint: (flowEntry: string) => Promise<void>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setFlowEntryPoint = exports.setLastPage = exports.initSourceDetails = exports.isSourcePresent = exports.readSourceCookie = void 0;
|
|
4
|
+
const cookie_1 = require("../cookie");
|
|
5
|
+
const SOURCE_DETAILS_COOKIE = 'source_details';
|
|
6
|
+
const UTM_PARAMS = [
|
|
7
|
+
'utm_source',
|
|
8
|
+
'utm_medium',
|
|
9
|
+
'utm_campaign',
|
|
10
|
+
'utm_term',
|
|
11
|
+
];
|
|
12
|
+
const readSourceCookie = () => {
|
|
13
|
+
const sourceDetails = (0, cookie_1.getCookie)(SOURCE_DETAILS_COOKIE);
|
|
14
|
+
return sourceDetails ? JSON.parse(decodeURIComponent(sourceDetails)) : undefined;
|
|
15
|
+
};
|
|
16
|
+
exports.readSourceCookie = readSourceCookie;
|
|
17
|
+
const writeSourceCookie = (sourceDetails) => {
|
|
18
|
+
(0, cookie_1.createCookie)(SOURCE_DETAILS_COOKIE, JSON.stringify(sourceDetails), 365, true);
|
|
19
|
+
};
|
|
20
|
+
const isSourcePresent = () => {
|
|
21
|
+
return !!(0, cookie_1.getCookie)(SOURCE_DETAILS_COOKIE);
|
|
22
|
+
};
|
|
23
|
+
exports.isSourcePresent = isSourcePresent;
|
|
24
|
+
const updateSourceCookie = (sourceDetail) => {
|
|
25
|
+
if (!exports.isSourcePresent)
|
|
26
|
+
return;
|
|
27
|
+
const sourceDetails = (0, exports.readSourceCookie)();
|
|
28
|
+
const updatedDetails = {
|
|
29
|
+
...sourceDetails,
|
|
30
|
+
...sourceDetail,
|
|
31
|
+
};
|
|
32
|
+
writeSourceCookie(updatedDetails);
|
|
33
|
+
};
|
|
34
|
+
const getRevenueChannel = (platform, utmParams) => {
|
|
35
|
+
let revenueChannel = 'unknown';
|
|
36
|
+
// set defaults for WEBSITE and ASTRO
|
|
37
|
+
if (platform === 'website') {
|
|
38
|
+
revenueChannel = 'organic';
|
|
39
|
+
}
|
|
40
|
+
else if (platform === 'astro') {
|
|
41
|
+
revenueChannel = 'performance';
|
|
42
|
+
}
|
|
43
|
+
if (utmParams) {
|
|
44
|
+
const { utm_source: utmSource = '' } = utmParams;
|
|
45
|
+
switch (true) {
|
|
46
|
+
case /^affiliate-/.test(utmSource):
|
|
47
|
+
revenueChannel = 'affiliate';
|
|
48
|
+
break;
|
|
49
|
+
case /^offline-/.test(utmSource):
|
|
50
|
+
revenueChannel = 'offline';
|
|
51
|
+
break;
|
|
52
|
+
case /^referral-/.test(utmSource):
|
|
53
|
+
revenueChannel = 'referral';
|
|
54
|
+
break;
|
|
55
|
+
case /^performance-/.test(utmSource):
|
|
56
|
+
revenueChannel = 'performance';
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return revenueChannel;
|
|
61
|
+
};
|
|
62
|
+
/*
|
|
63
|
+
if Platform = website, then decide based on experiment key
|
|
64
|
+
if Platform = Astro, decide logic once BAU is started
|
|
65
|
+
if Platform = APP, decide logic
|
|
66
|
+
if Platform = chatbot, decide based on chatbot experiment key
|
|
67
|
+
*/
|
|
68
|
+
const getFlow = (platform, experiments) => {
|
|
69
|
+
let flow = 'regular';
|
|
70
|
+
if (platform === 'website') {
|
|
71
|
+
if (experiments) {
|
|
72
|
+
const ecnaExp = Object.keys(experiments).find(experiment => experiment.indexOf('ecna') !== -1);
|
|
73
|
+
flow = ecnaExp && experiments[ecnaExp] === 'b' ? 'e-cna' : 'regular';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return flow;
|
|
77
|
+
};
|
|
78
|
+
const getUTMParams = () => {
|
|
79
|
+
if (typeof window === undefined)
|
|
80
|
+
return;
|
|
81
|
+
const search = new URLSearchParams(window.location.search);
|
|
82
|
+
const utmParams = UTM_PARAMS.reduce((acc, param) => {
|
|
83
|
+
const utmParam = search.get(param);
|
|
84
|
+
if (utmParam) {
|
|
85
|
+
acc[param] = utmParam;
|
|
86
|
+
}
|
|
87
|
+
return acc;
|
|
88
|
+
}, {});
|
|
89
|
+
return utmParams;
|
|
90
|
+
};
|
|
91
|
+
const getFirstPage = () => {
|
|
92
|
+
if (typeof window === undefined)
|
|
93
|
+
return '';
|
|
94
|
+
return window.location.pathname;
|
|
95
|
+
};
|
|
96
|
+
/* TODO: Align Marketing Team on UTM source convention
|
|
97
|
+
affiliate-<channel>
|
|
98
|
+
performance-<channel>
|
|
99
|
+
organic-<channel>
|
|
100
|
+
offline-<channel>
|
|
101
|
+
*/
|
|
102
|
+
const getChannel = (utmParams) => {
|
|
103
|
+
// TODO: UTM source patter for FB, GOOGLE...
|
|
104
|
+
if (!utmParams)
|
|
105
|
+
return '';
|
|
106
|
+
const { utm_source: utmSource = '' } = utmParams;
|
|
107
|
+
return utmSource.split('-')[1];
|
|
108
|
+
};
|
|
109
|
+
/*
|
|
110
|
+
Set Static Source Details of user on Visit of Platform
|
|
111
|
+
*/
|
|
112
|
+
const initSourceDetails = async ({ platform, experiments, flow, affiliateChannel, offlineChannel, organicChannel, performanceChannel, revenueChannel, }) => {
|
|
113
|
+
if (!(0, exports.isSourcePresent)()) {
|
|
114
|
+
const utmParams = getUTMParams();
|
|
115
|
+
const leadChannel = getChannel(utmParams);
|
|
116
|
+
revenueChannel = revenueChannel || getRevenueChannel(platform, utmParams);
|
|
117
|
+
affiliateChannel =
|
|
118
|
+
revenueChannel === 'affiliate' ? affiliateChannel || leadChannel : undefined;
|
|
119
|
+
offlineChannel =
|
|
120
|
+
revenueChannel === 'offline' ? offlineChannel || leadChannel : undefined;
|
|
121
|
+
organicChannel =
|
|
122
|
+
revenueChannel === 'organic' ? organicChannel || leadChannel : undefined;
|
|
123
|
+
performanceChannel =
|
|
124
|
+
revenueChannel === 'performance' ? performanceChannel || leadChannel : undefined;
|
|
125
|
+
const sourceDetails = {
|
|
126
|
+
platform,
|
|
127
|
+
experiments,
|
|
128
|
+
utmParams: getUTMParams(),
|
|
129
|
+
flow: flow || getFlow(platform, experiments),
|
|
130
|
+
affiliateChannel,
|
|
131
|
+
offlineChannel,
|
|
132
|
+
organicChannel,
|
|
133
|
+
performanceChannel,
|
|
134
|
+
revenueChannel: revenueChannel,
|
|
135
|
+
firstPage: getFirstPage(),
|
|
136
|
+
};
|
|
137
|
+
writeSourceCookie(sourceDetails);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
exports.initSourceDetails = initSourceDetails;
|
|
141
|
+
// Last Page which user visited signup before
|
|
142
|
+
const setLastPage = async (pagePath) => {
|
|
143
|
+
updateSourceCookie({ lastPage: pagePath });
|
|
144
|
+
};
|
|
145
|
+
exports.setLastPage = setLastPage;
|
|
146
|
+
// set Entry point where user clicked to Signup
|
|
147
|
+
const setFlowEntryPoint = async (flowEntry) => {
|
|
148
|
+
updateSourceCookie({ flowEntry });
|
|
149
|
+
};
|
|
150
|
+
exports.setFlowEntryPoint = setFlowEntryPoint;
|
|
151
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/growth-source/index.ts"],"names":[],"mappings":";;;AAUA,sCAAoD;AAEpD,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAC/C,MAAM,UAAU,GAAoB;IAClC,YAAY;IACZ,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,SAAS,CAAC;QAC/E,cAAc;YACZ,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,cAAc;YACZ,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,kBAAkB;YAChB,cAAc,KAAK,aAAa,CAAC,CAAC,CAAC,kBAAkB,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;QAEnF,MAAM,aAAa,GAAkB;YACnC,QAAQ;YACR,WAAW;YACX,SAAS,EAAE,YAAY,EAAE;YACzB,IAAI,EAAE,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC;YAC5C,gBAAgB;YAChB,cAAc;YACd,cAAc;YACd,kBAAkB;YAClB,cAAc,EAAE,cAAc;YAC9B,SAAS,EAAE,YAAY,EAAE;SAC1B,CAAC;QAEF,iBAAiB,CAAC,aAAa,CAAC,CAAC;KAClC;AACH,CAAC,CAAC;AAvCW,QAAA,iBAAiB,qBAuC5B;AAEF,6CAA6C;AACtC,MAAM,WAAW,GAAG,KAAK,EAAE,QAAgB,EAAiB,EAAE;IACnE,kBAAkB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC7C,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB;AAEF,+CAA+C;AACxC,MAAM,iBAAiB,GAAG,KAAK,EAAE,SAAiB,EAAiB,EAAE;IAC1E,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;AACpC,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Platform = 'website' | 'app' | 'astro' | 'leap-teacher' | 'leap-admin';
|
|
2
|
+
export type RevenueChannel = 'organic' | 'performance' | 'affiliate' | 'offline' | 'referral' | 'unknown';
|
|
3
|
+
export type SignupFlow = 'regular' | 'e-cna' | 'e-sales';
|
|
4
|
+
export type Experiments = Record<string, unknown>;
|
|
5
|
+
export type UTMParams = {
|
|
6
|
+
utm_source?: string;
|
|
7
|
+
utm_medium?: string;
|
|
8
|
+
utm_campaign?: string;
|
|
9
|
+
utm_term?: string;
|
|
10
|
+
};
|
|
11
|
+
export type UTMParamsKeys = keyof UTMParams;
|
|
12
|
+
export type SourceDetails = {
|
|
13
|
+
platform: Platform;
|
|
14
|
+
experiments?: Experiments;
|
|
15
|
+
flow?: SignupFlow;
|
|
16
|
+
utmParams?: UTMParams;
|
|
17
|
+
affiliateChannel?: string;
|
|
18
|
+
offlineChannel?: string;
|
|
19
|
+
performanceChannel?: string;
|
|
20
|
+
revenueChannel: RevenueChannel;
|
|
21
|
+
organicChannel?: string;
|
|
22
|
+
flowEntry?: string;
|
|
23
|
+
firstPage?: string;
|
|
24
|
+
lastPage?: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/growth-source/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,10 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./cookie"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./local-storage"), exports);
|
|
20
|
-
__exportStar(require("./e-cna"), exports);
|
|
21
|
-
__exportStar(require("./date-time-helper"), exports);
|
|
22
|
-
__exportStar(require("./country"), exports);
|
|
23
|
-
__exportStar(require("./object"), exports);
|
|
18
|
+
__exportStar(require("./growth-source"), exports);
|
|
24
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,kDAAgC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuemath/web-utils",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Shared web utils package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"build-watch": "tsc -w",
|
|
10
10
|
"prepublishOnly": "rm -rf dist && yarn build",
|
|
11
|
-
"prepare": "husky install"
|
|
12
|
-
"precommit": "lint-staged",
|
|
13
|
-
"release": "lerna publish from-package"
|
|
11
|
+
"prepare": "husky install"
|
|
14
12
|
},
|
|
15
13
|
"repository": {
|
|
16
14
|
"type": "git",
|
|
@@ -39,8 +37,6 @@
|
|
|
39
37
|
"prettier": "2.4.1",
|
|
40
38
|
"typescript": "4.9.4"
|
|
41
39
|
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"dayjs": "^1.11.7"
|
|
44
|
-
},
|
|
40
|
+
"dependencies": {},
|
|
45
41
|
"side-effects": false
|
|
46
42
|
}
|
package/src/cookie/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
export const getCookie = (name: string, cookie: string = document.cookie): string => {
|
|
3
2
|
if (!cookie) {
|
|
4
3
|
return '';
|
|
@@ -29,7 +28,12 @@ export function removeCookie(name: string): void {
|
|
|
29
28
|
document.cookie = `${name}=; expires=${date.toUTCString()}; path=/`;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
export function createCookie(
|
|
31
|
+
export function createCookie(
|
|
32
|
+
name: string,
|
|
33
|
+
value: string,
|
|
34
|
+
days: number,
|
|
35
|
+
subdomain: boolean,
|
|
36
|
+
): void {
|
|
33
37
|
let expires = '';
|
|
34
38
|
|
|
35
39
|
if (days) {
|
|
@@ -38,7 +42,9 @@ export function createCookie(name: string, value: string, days: number): void {
|
|
|
38
42
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
39
43
|
expires = `; expires=${date.toUTCString()}`;
|
|
40
44
|
}
|
|
41
|
-
document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path
|
|
45
|
+
document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=/${
|
|
46
|
+
subdomain ? '; domain=cuemath.com' : ''
|
|
47
|
+
}`;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
export function createCookieWithMidnightExp(name: string, value: string): void {
|
|
@@ -48,4 +54,4 @@ export function createCookieWithMidnightExp(name: string, value: string): void {
|
|
|
48
54
|
const expires = `; expires=${date}`;
|
|
49
55
|
|
|
50
56
|
document.cookie = `${name}=${value}${expires}; path=/`;
|
|
51
|
-
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SourceDetails,
|
|
3
|
+
Platform,
|
|
4
|
+
SignupFlow,
|
|
5
|
+
UTMParams,
|
|
6
|
+
Experiments,
|
|
7
|
+
RevenueChannel,
|
|
8
|
+
UTMParamsKeys,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
import { createCookie, getCookie } from '../cookie';
|
|
12
|
+
|
|
13
|
+
const SOURCE_DETAILS_COOKIE = 'source_details';
|
|
14
|
+
const UTM_PARAMS: UTMParamsKeys[] = [
|
|
15
|
+
'utm_source',
|
|
16
|
+
'utm_medium',
|
|
17
|
+
'utm_campaign',
|
|
18
|
+
'utm_term',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export const readSourceCookie = (): SourceDetails => {
|
|
22
|
+
const sourceDetails = getCookie(SOURCE_DETAILS_COOKIE);
|
|
23
|
+
|
|
24
|
+
return sourceDetails ? JSON.parse(decodeURIComponent(sourceDetails)) : undefined;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const writeSourceCookie = (sourceDetails: SourceDetails): void => {
|
|
28
|
+
createCookie(SOURCE_DETAILS_COOKIE, JSON.stringify(sourceDetails), 365, true);
|
|
29
|
+
};
|
|
30
|
+
|
|
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
|
+
|
|
38
|
+
const sourceDetails: SourceDetails = readSourceCookie();
|
|
39
|
+
const updatedDetails: SourceDetails = {
|
|
40
|
+
...sourceDetails,
|
|
41
|
+
...sourceDetail,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
writeSourceCookie(updatedDetails);
|
|
45
|
+
};
|
|
46
|
+
|
|
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
|
+
}
|
|
56
|
+
|
|
57
|
+
if (utmParams) {
|
|
58
|
+
const { utm_source: utmSource = '' } = utmParams;
|
|
59
|
+
|
|
60
|
+
switch (true) {
|
|
61
|
+
case /^affiliate-/.test(utmSource):
|
|
62
|
+
revenueChannel = 'affiliate';
|
|
63
|
+
break;
|
|
64
|
+
case /^offline-/.test(utmSource):
|
|
65
|
+
revenueChannel = 'offline';
|
|
66
|
+
break;
|
|
67
|
+
case /^referral-/.test(utmSource):
|
|
68
|
+
revenueChannel = 'referral';
|
|
69
|
+
break;
|
|
70
|
+
case /^performance-/.test(utmSource):
|
|
71
|
+
revenueChannel = 'performance';
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return revenueChannel;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
if Platform = website, then decide based on experiment key
|
|
81
|
+
if Platform = Astro, decide logic once BAU is started
|
|
82
|
+
if Platform = APP, decide logic
|
|
83
|
+
if Platform = chatbot, decide based on chatbot experiment key
|
|
84
|
+
*/
|
|
85
|
+
const getFlow = (platform: Platform, experiments?: Experiments): SignupFlow => {
|
|
86
|
+
let flow: SignupFlow = 'regular';
|
|
87
|
+
|
|
88
|
+
if (platform === 'website') {
|
|
89
|
+
if (experiments) {
|
|
90
|
+
const ecnaExp = Object.keys(experiments).find(
|
|
91
|
+
experiment => experiment.indexOf('ecna') !== -1,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
flow = ecnaExp && experiments[ecnaExp] === 'b' ? 'e-cna' : 'regular';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return flow;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const getUTMParams = (): UTMParams | undefined => {
|
|
102
|
+
if (typeof window === undefined) return;
|
|
103
|
+
|
|
104
|
+
const search = new URLSearchParams(window.location.search);
|
|
105
|
+
const utmParams = UTM_PARAMS.reduce((acc: UTMParams, param) => {
|
|
106
|
+
const utmParam = search.get(param) as string;
|
|
107
|
+
|
|
108
|
+
if (utmParam) {
|
|
109
|
+
acc[param] = utmParam;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return acc;
|
|
113
|
+
}, {});
|
|
114
|
+
|
|
115
|
+
return utmParams;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const getFirstPage = (): string => {
|
|
119
|
+
if (typeof window === undefined) return '';
|
|
120
|
+
|
|
121
|
+
return window.location.pathname;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/* TODO: Align Marketing Team on UTM source convention
|
|
125
|
+
affiliate-<channel>
|
|
126
|
+
performance-<channel>
|
|
127
|
+
organic-<channel>
|
|
128
|
+
offline-<channel>
|
|
129
|
+
*/
|
|
130
|
+
const getChannel = (utmParams: UTMParams | undefined): string => {
|
|
131
|
+
// TODO: UTM source patter for FB, GOOGLE...
|
|
132
|
+
if (!utmParams) return '';
|
|
133
|
+
|
|
134
|
+
const { utm_source: utmSource = '' } = utmParams;
|
|
135
|
+
|
|
136
|
+
return utmSource.split('-')[1];
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
Set Static Source Details of user on Visit of Platform
|
|
141
|
+
*/
|
|
142
|
+
export const initSourceDetails = async ({
|
|
143
|
+
platform,
|
|
144
|
+
experiments,
|
|
145
|
+
flow,
|
|
146
|
+
affiliateChannel,
|
|
147
|
+
offlineChannel,
|
|
148
|
+
organicChannel,
|
|
149
|
+
performanceChannel,
|
|
150
|
+
revenueChannel,
|
|
151
|
+
}: SourceDetails): Promise<void> => {
|
|
152
|
+
if (!isSourcePresent()) {
|
|
153
|
+
const utmParams = getUTMParams();
|
|
154
|
+
const leadChannel = getChannel(utmParams);
|
|
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
|
+
|
|
166
|
+
const sourceDetails: SourceDetails = {
|
|
167
|
+
platform,
|
|
168
|
+
experiments,
|
|
169
|
+
utmParams: getUTMParams(),
|
|
170
|
+
flow: flow || getFlow(platform, experiments),
|
|
171
|
+
affiliateChannel,
|
|
172
|
+
offlineChannel,
|
|
173
|
+
organicChannel,
|
|
174
|
+
performanceChannel,
|
|
175
|
+
revenueChannel: revenueChannel,
|
|
176
|
+
firstPage: getFirstPage(),
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
writeSourceCookie(sourceDetails);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// Last Page which user visited signup before
|
|
184
|
+
export const setLastPage = async (pagePath: string): Promise<void> => {
|
|
185
|
+
updateSourceCookie({ lastPage: pagePath });
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// set Entry point where user clicked to Signup
|
|
189
|
+
export const setFlowEntryPoint = async (flowEntry: string): Promise<void> => {
|
|
190
|
+
updateSourceCookie({ flowEntry });
|
|
191
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type Platform = 'website' | 'app' | 'astro' | 'leap-teacher' | 'leap-admin';
|
|
2
|
+
export type RevenueChannel =
|
|
3
|
+
| 'organic'
|
|
4
|
+
| 'performance'
|
|
5
|
+
| 'affiliate'
|
|
6
|
+
| 'offline'
|
|
7
|
+
| 'referral'
|
|
8
|
+
| 'unknown';
|
|
9
|
+
export type SignupFlow = 'regular' | 'e-cna' | 'e-sales';
|
|
10
|
+
export type Experiments = Record<string, unknown>;
|
|
11
|
+
export type UTMParams = {
|
|
12
|
+
utm_source?: string;
|
|
13
|
+
utm_medium?: string;
|
|
14
|
+
utm_campaign?: string;
|
|
15
|
+
utm_term?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type UTMParamsKeys = keyof UTMParams;
|
|
19
|
+
|
|
20
|
+
export type SourceDetails = {
|
|
21
|
+
platform: Platform;
|
|
22
|
+
experiments?: Experiments;
|
|
23
|
+
flow?: SignupFlow;
|
|
24
|
+
utmParams?: UTMParams;
|
|
25
|
+
affiliateChannel?: string;
|
|
26
|
+
offlineChannel?: string;
|
|
27
|
+
performanceChannel?: string;
|
|
28
|
+
revenueChannel: RevenueChannel;
|
|
29
|
+
organicChannel?: string;
|
|
30
|
+
flowEntry?: string;
|
|
31
|
+
firstPage?: string;
|
|
32
|
+
lastPage?: string;
|
|
33
|
+
};
|
package/src/index.ts
CHANGED
package/.eslintignore
DELETED
package/.huskyrc
DELETED
package/.lintstagedrc.yml
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CUE_COUNTRY_CODE_KEY = exports.ISO_COUNTRY_CODE = void 0;
|
|
4
|
-
var iso_country_code_1 = require("./iso-country-code");
|
|
5
|
-
Object.defineProperty(exports, "ISO_COUNTRY_CODE", { enumerable: true, get: function () { return iso_country_code_1.COUNTRY_NAME_COUNTRY_CODE_MAP; } });
|
|
6
|
-
exports.CUE_COUNTRY_CODE_KEY = 'cue_country_code';
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/country/index.ts"],"names":[],"mappings":";;;AAAA,uDAAuF;AAA9E,oHAAA,6BAA6B,OAAoB;AAC7C,QAAA,oBAAoB,GAAG,kBAAkB,CAAC"}
|