@cuemath/web-utils 1.0.3 → 1.0.5-beta.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/dist/cookie/index.d.ts +1 -1
- package/dist/cookie/index.js +2 -2
- package/dist/cookie/index.js.map +1 -1
- package/dist/e-cna/index.d.ts +4 -0
- package/dist/e-cna/index.js +22 -0
- package/dist/e-cna/index.js.map +1 -0
- package/dist/growth-source/index.d.ts +1 -1
- package/dist/growth-source/index.js +22 -2
- package/dist/growth-source/index.js.map +1 -1
- package/dist/growth-source/types.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package-lock.json +3274 -0
- package/package.json +3 -2
- package/src/cookie/index.ts +4 -2
- package/src/e-cna/index.ts +23 -0
- package/src/growth-source/index.ts +26 -2
- package/src/growth-source/types.ts +2 -0
- package/src/index.ts +1 -0
- package/dist/date-time-helper/e-cna/index.d.ts +0 -4
- package/dist/date-time-helper/e-cna/index.js +0 -40
- package/dist/date-time-helper/e-cna/index.js.map +0 -1
- package/src/date-time-helper/e-cna/index.ts +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuemath/web-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5-beta.0",
|
|
4
4
|
"description": "Shared web utils package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@types/node": "^18.11.18",
|
|
44
|
-
"dayjs": "^1.11.7"
|
|
44
|
+
"dayjs": "^1.11.7",
|
|
45
|
+
"yarn": "^1.22.19"
|
|
45
46
|
}
|
|
46
47
|
}
|
package/src/cookie/index.ts
CHANGED
|
@@ -18,14 +18,16 @@ export const getCookie = (name: string, cookie: string = document.cookie): strin
|
|
|
18
18
|
return '';
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export function removeCookie(name: string): void {
|
|
21
|
+
export function removeCookie(name: string, subdomain?: boolean): void {
|
|
22
22
|
const date = new Date();
|
|
23
23
|
|
|
24
24
|
// Set it expire in -1 days
|
|
25
25
|
date.setTime(date.getTime() + -1 * 24 * 60 * 60 * 1000);
|
|
26
26
|
|
|
27
27
|
// Set it
|
|
28
|
-
document.cookie = `${name}=; expires=${date.toUTCString()}; path
|
|
28
|
+
document.cookie = `${name}=; expires=${date.toUTCString()}; path=/${
|
|
29
|
+
subdomain ? '; domain=cuemath.com' : ''
|
|
30
|
+
}`;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export function createCookie(
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TWENTY_FOUR_HOURS_IN_SECONDS } from '../constants/date-time';
|
|
2
|
+
import { getCurrentDatebyTimezone } from '../date-time-helper/index';
|
|
3
|
+
|
|
4
|
+
// if adding any change in this function, then need update at all the places where we are using this function in website and astro
|
|
5
|
+
export const getDates = (
|
|
6
|
+
timezone: string,
|
|
7
|
+
): Array<{ futureDate: number; disabled: boolean }> => {
|
|
8
|
+
const currentDate = Date.parse(getCurrentDatebyTimezone(timezone)) / 1000;
|
|
9
|
+
const dates = [];
|
|
10
|
+
|
|
11
|
+
const days = 10;
|
|
12
|
+
const buffer = 2;
|
|
13
|
+
|
|
14
|
+
// getting dates by adding 86400 seconds(24 hours)
|
|
15
|
+
for (let i = 0; i < days; i += 1) {
|
|
16
|
+
dates.push({
|
|
17
|
+
futureDate: currentDate + TWENTY_FOUR_HOURS_IN_SECONDS * i,
|
|
18
|
+
disabled: !(i > buffer),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return dates;
|
|
23
|
+
};
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
UTMParamsKeys,
|
|
10
10
|
} from './types';
|
|
11
11
|
|
|
12
|
-
import { createCookie, getCookie } from '../cookie';
|
|
12
|
+
import { createCookie, getCookie, removeCookie } from '../cookie';
|
|
13
13
|
|
|
14
14
|
const SOURCE_DETAILS_COOKIE = 'source_details';
|
|
15
15
|
const UTM_PARAMS: UTMParamsKeys[] = [
|
|
@@ -130,7 +130,22 @@ const getChannel = (utmSource?: string): string => {
|
|
|
130
130
|
// TODO: UTM source patter for FB, GOOGLE...
|
|
131
131
|
if (!utmSource) return '';
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
let channel = '';
|
|
134
|
+
|
|
135
|
+
if (utmSource) {
|
|
136
|
+
switch (true) {
|
|
137
|
+
case /^affiliate-/.test(utmSource):
|
|
138
|
+
case /^offline-/.test(utmSource):
|
|
139
|
+
case /^referral-/.test(utmSource):
|
|
140
|
+
case /^performance-/.test(utmSource):
|
|
141
|
+
channel = utmSource.split('-')[1];
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return channel;
|
|
134
149
|
};
|
|
135
150
|
|
|
136
151
|
/*
|
|
@@ -145,11 +160,18 @@ export const initSourceDetails = async ({
|
|
|
145
160
|
organicChannel,
|
|
146
161
|
performanceChannel,
|
|
147
162
|
revenueChannel,
|
|
163
|
+
guestId
|
|
148
164
|
}: SourceDetails): Promise<void> => {
|
|
149
165
|
const utmParams: Partial<UTMParams> = getUTMParams();
|
|
150
166
|
const { utm_source: utmSource } = utmParams;
|
|
151
167
|
const leadChannel = getChannel(utmSource);
|
|
152
168
|
|
|
169
|
+
/*
|
|
170
|
+
source cookie was added in cross subdomain for few days initially,
|
|
171
|
+
which was later changed to subdomain specific. Now to sending older cookie to backend, removing older cookie
|
|
172
|
+
*/
|
|
173
|
+
removeCookie(SOURCE_DETAILS_COOKIE, true);
|
|
174
|
+
|
|
153
175
|
revenueChannel = revenueChannel || getRevenueChannel(platform, utmSource);
|
|
154
176
|
|
|
155
177
|
if (utmSource) {
|
|
@@ -175,6 +197,7 @@ export const initSourceDetails = async ({
|
|
|
175
197
|
performance_channel: performanceChannel,
|
|
176
198
|
revenue_channel: revenueChannel,
|
|
177
199
|
first_page: getFirstPage(),
|
|
200
|
+
guest_id: guestId
|
|
178
201
|
};
|
|
179
202
|
|
|
180
203
|
writeSourceCookie(sourceDetails);
|
|
@@ -182,6 +205,7 @@ export const initSourceDetails = async ({
|
|
|
182
205
|
let updatedSource: Partial<SourceDetailsCookie> = {
|
|
183
206
|
experiment_dict: experiments,
|
|
184
207
|
flow: flow || getFlow(platform, experiments),
|
|
208
|
+
guest_id: guestId,
|
|
185
209
|
};
|
|
186
210
|
|
|
187
211
|
if (utmSource) {
|
|
@@ -30,6 +30,7 @@ export type SourceDetailsCookie = {
|
|
|
30
30
|
flow_entry?: string;
|
|
31
31
|
first_page?: string;
|
|
32
32
|
last_page?: string;
|
|
33
|
+
guest_id?: string;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
export type SourceDetails = {
|
|
@@ -45,4 +46,5 @@ export type SourceDetails = {
|
|
|
45
46
|
flowEntry?: string;
|
|
46
47
|
firstPage?: string;
|
|
47
48
|
lastPage?: string;
|
|
49
|
+
guestId?: string;
|
|
48
50
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDates = void 0;
|
|
4
|
-
const index_1 = require("../../constants/country/index");
|
|
5
|
-
const date_time_1 = require("../../constants/date-time");
|
|
6
|
-
const index_2 = require("../index");
|
|
7
|
-
const getDates = (timezone, platform, country) => {
|
|
8
|
-
const currentDate = Date.parse((0, index_2.getCurrentDatebyTimezone)(timezone)) / 1000;
|
|
9
|
-
const dates = [];
|
|
10
|
-
let days = 7;
|
|
11
|
-
let buffer = 1;
|
|
12
|
-
switch (platform) {
|
|
13
|
-
case 'astro':
|
|
14
|
-
if (country === index_1.ISO_COUNTRY_CODE.INDIA) {
|
|
15
|
-
days = 10;
|
|
16
|
-
buffer = 2;
|
|
17
|
-
}
|
|
18
|
-
break;
|
|
19
|
-
case 'website':
|
|
20
|
-
if (country === index_1.ISO_COUNTRY_CODE.INDIA) {
|
|
21
|
-
days = 10;
|
|
22
|
-
buffer = 2;
|
|
23
|
-
}
|
|
24
|
-
break;
|
|
25
|
-
default:
|
|
26
|
-
days = 7;
|
|
27
|
-
buffer = 1;
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
// getting dates by adding 86400 seconds(24 hours)
|
|
31
|
-
for (let i = 0; i < days; i += 1) {
|
|
32
|
-
dates.push({
|
|
33
|
-
futureDate: currentDate + date_time_1.TWENTY_FOUR_HOURS_IN_SECONDS * i,
|
|
34
|
-
disabled: !(i > buffer),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return dates;
|
|
38
|
-
};
|
|
39
|
-
exports.getDates = getDates;
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date-time-helper/e-cna/index.ts"],"names":[],"mappings":";;;AAAA,yDAAiE;AACjE,yDAAyE;AACzE,oCAAoD;AAE7C,MAAM,QAAQ,GAAG,CACtB,QAAgB,EAChB,QAAgB,EAChB,OAAe,EACmC,EAAE;IACpD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,gCAAwB,EAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC;IAC1E,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,QAAQ,QAAQ,EAAE;QAChB,KAAK,OAAO;YACV,IAAI,OAAO,KAAK,wBAAgB,CAAC,KAAK,EAAE;gBACtC,IAAI,GAAG,EAAE,CAAC;gBACV,MAAM,GAAG,CAAC,CAAC;aACZ;YACD,MAAM;QACR,KAAK,SAAS;YACZ,IAAI,OAAO,KAAK,wBAAgB,CAAC,KAAK,EAAE;gBACtC,IAAI,GAAG,EAAE,CAAC;gBACV,MAAM,GAAG,CAAC,CAAC;aACZ;YACD,MAAM;QACR;YACE,IAAI,GAAG,CAAC,CAAC;YACT,MAAM,GAAG,CAAC,CAAC;YACX,MAAM;KACT;IAED,kDAAkD;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE;QAChC,KAAK,CAAC,IAAI,CAAC;YACT,UAAU,EAAE,WAAW,GAAG,wCAA4B,GAAG,CAAC;YAC1D,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;SACxB,CAAC,CAAC;KACJ;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAvCW,QAAA,QAAQ,YAuCnB"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ISO_COUNTRY_CODE } from '../../constants/country/index';
|
|
2
|
-
import { TWENTY_FOUR_HOURS_IN_SECONDS } from '../../constants/date-time';
|
|
3
|
-
import { getCurrentDatebyTimezone } from '../index';
|
|
4
|
-
|
|
5
|
-
export const getDates = (
|
|
6
|
-
timezone: string,
|
|
7
|
-
platform: string,
|
|
8
|
-
country: string,
|
|
9
|
-
): Array<{ futureDate: number; disabled: boolean }> => {
|
|
10
|
-
const currentDate = Date.parse(getCurrentDatebyTimezone(timezone)) / 1000;
|
|
11
|
-
const dates = [];
|
|
12
|
-
|
|
13
|
-
let days = 7;
|
|
14
|
-
let buffer = 1;
|
|
15
|
-
|
|
16
|
-
switch (platform) {
|
|
17
|
-
case 'astro':
|
|
18
|
-
if (country === ISO_COUNTRY_CODE.INDIA) {
|
|
19
|
-
days = 10;
|
|
20
|
-
buffer = 2;
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
case 'website':
|
|
24
|
-
if (country === ISO_COUNTRY_CODE.INDIA) {
|
|
25
|
-
days = 10;
|
|
26
|
-
buffer = 2;
|
|
27
|
-
}
|
|
28
|
-
break;
|
|
29
|
-
default:
|
|
30
|
-
days = 7;
|
|
31
|
-
buffer = 1;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// getting dates by adding 86400 seconds(24 hours)
|
|
36
|
-
for (let i = 0; i < days; i += 1) {
|
|
37
|
-
dates.push({
|
|
38
|
-
futureDate: currentDate + TWENTY_FOUR_HOURS_IN_SECONDS * i,
|
|
39
|
-
disabled: !(i > buffer),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return dates;
|
|
44
|
-
};
|