@uncinc/uncinc-react-kitchen-sink 2.8.22 → 2.8.23
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/helpers/utm.d.ts +16 -0
- package/dist/helpers/utm.js +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add UTM parameters to cookie with 15 minutes expire
|
|
3
|
+
* @returns {void}
|
|
4
|
+
*/
|
|
5
|
+
export function setUtmCookies(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Get the cookies that start with utm_ from the document
|
|
8
|
+
* @returns {Array} An array of utm cookies
|
|
9
|
+
*/
|
|
10
|
+
export function getUtmCookies(): any[];
|
|
11
|
+
/**
|
|
12
|
+
* Add the cookies from the document a url
|
|
13
|
+
* @param {string} href - The URL we would like to add utm cookies to
|
|
14
|
+
* @returns {string | null} the mutated URL or nothing
|
|
15
|
+
*/
|
|
16
|
+
export function addUtmQueryString(href: string): string | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import qs from 'query-string';
|
|
2
|
+
import Cookies from 'js-cookie';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Add UTM parameters to cookie with 15 minutes expire
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*/
|
|
8
|
+
export function setUtmCookies() {
|
|
9
|
+
var inFifteenMinutes = new Date(new Date().getTime() + 15 * 60 * 1000);
|
|
10
|
+
var params = qs.parse(window.location.search);
|
|
11
|
+
var utmKeys = Object.keys(params).filter(function (value) {
|
|
12
|
+
return value.startsWith('utm_');
|
|
13
|
+
});
|
|
14
|
+
utmKeys.forEach(function (key) {
|
|
15
|
+
Cookies.set(key, params[key], {
|
|
16
|
+
expires: inFifteenMinutes
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the cookies that start with utm_ from the document
|
|
23
|
+
* @returns {Array} An array of utm cookies
|
|
24
|
+
*/
|
|
25
|
+
export function getUtmCookies() {
|
|
26
|
+
return document.cookie.split(';').map(function (cookie) {
|
|
27
|
+
return cookie.trim();
|
|
28
|
+
}).filter(function (value) {
|
|
29
|
+
return value.startsWith('utm_');
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Add the cookies from the document a url
|
|
35
|
+
* @param {string} href - The URL we would like to add utm cookies to
|
|
36
|
+
* @returns {string | null} the mutated URL or nothing
|
|
37
|
+
*/
|
|
38
|
+
export function addUtmQueryString(href) {
|
|
39
|
+
if (!href) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
var utmQueryString = getUtmCookies().join('&');
|
|
43
|
+
if (utmQueryString) {
|
|
44
|
+
href += (href.split('?')[1] ? '&' : '?') + utmQueryString;
|
|
45
|
+
}
|
|
46
|
+
return href;
|
|
47
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -80,4 +80,5 @@ export { default as useValueForCurrentViewPort } from "./helpers/useValueForCurr
|
|
|
80
80
|
export { getApiAutoCompleteSuggestions } from "./helpers/apiAutoComplete";
|
|
81
81
|
export { default as FormikWrapper, FormikExtendedContextProvider } from "./components/Form/FormikWrapper";
|
|
82
82
|
export { parseDateWithTimezoneOffset, isValidDate, doubleDigits } from "./helpers/date";
|
|
83
|
+
export { setUtmCookies, getUtmCookies, addUtmQueryString } from "./helpers/utm";
|
|
83
84
|
export { isExternalLink, normalizeLink } from "./helpers/link";
|
package/dist/index.js
CHANGED
|
@@ -93,5 +93,6 @@ export { default as useWindowDimensions } from './hooks/useWindowDimensions';
|
|
|
93
93
|
export { default as gtm } from './helpers/gtm';
|
|
94
94
|
export { default as useValueForCurrentViewPort } from './helpers/useValueForCurrentViewPort';
|
|
95
95
|
export { parseDateWithTimezoneOffset, isValidDate, doubleDigits } from './helpers/date';
|
|
96
|
+
export { setUtmCookies, getUtmCookies, addUtmQueryString } from './helpers/utm';
|
|
96
97
|
export { isExternalLink, normalizeLink } from './helpers/link';
|
|
97
98
|
export { getApiAutoCompleteSuggestions } from './helpers/apiAutoComplete';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uncinc/uncinc-react-kitchen-sink",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.23",
|
|
4
4
|
"description": "Default React components that are easily extended.",
|
|
5
5
|
"author": "uncinc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -148,6 +148,7 @@
|
|
|
148
148
|
"jest-junit": "^16.0.0",
|
|
149
149
|
"nodemon": "^3.0.3",
|
|
150
150
|
"prop-types": "^15.8.1",
|
|
151
|
+
"query-string": "^6.13.1",
|
|
151
152
|
"react-scripts": "^5.0.1",
|
|
152
153
|
"react-test-renderer": "^18.2.0",
|
|
153
154
|
"sinon": "^9.0.2",
|