@pack/react 0.1.2 → 0.1.3
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.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type BrowserData = {
|
|
2
|
+
userAgent: string;
|
|
3
|
+
pathname: string;
|
|
4
|
+
query: string;
|
|
5
|
+
screen: string;
|
|
6
|
+
referrer: string;
|
|
7
|
+
hostname: string;
|
|
8
|
+
language: string;
|
|
9
|
+
locale: string;
|
|
10
|
+
userTimeZone: string;
|
|
11
|
+
connection: string;
|
|
12
|
+
deviceCategory: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function usePackTrack(): void;
|
|
16
|
+
//# sourceMappingURL=pack-analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack-analytics.d.ts","sourceRoot":"","sources":["../../src/preview/pack-analytics.tsx"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAiDF,wBAAgB,YAAY,SA0B3B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
function getBrowserData() {
|
|
3
|
+
let userTimeZone;
|
|
4
|
+
let userLocale;
|
|
5
|
+
try {
|
|
6
|
+
userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
7
|
+
userLocale =
|
|
8
|
+
navigator.languages && navigator.languages.length
|
|
9
|
+
? navigator.languages[0]
|
|
10
|
+
: navigator.userLanguage ||
|
|
11
|
+
navigator.language ||
|
|
12
|
+
navigator.browserLanguage ||
|
|
13
|
+
"unknown";
|
|
14
|
+
}
|
|
15
|
+
catch (error) { }
|
|
16
|
+
const connection = navigator.connection ||
|
|
17
|
+
navigator.mozConnection ||
|
|
18
|
+
navigator.webkitConnection;
|
|
19
|
+
const minWidth = 768;
|
|
20
|
+
// prettier-ignore
|
|
21
|
+
const hasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
22
|
+
let deviceCategory = "desktop";
|
|
23
|
+
if (hasTouchSupport) {
|
|
24
|
+
const hasSmallScreen = window.screen.width < minWidth;
|
|
25
|
+
deviceCategory = hasSmallScreen ? "mobile" : "tablet";
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
userAgent: window.navigator.userAgent,
|
|
29
|
+
pathname: window.location.pathname,
|
|
30
|
+
query: window.location.search,
|
|
31
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
32
|
+
referrer: document.referrer,
|
|
33
|
+
hostname: window.location.hostname,
|
|
34
|
+
language: navigator.language,
|
|
35
|
+
locale: userLocale,
|
|
36
|
+
userTimeZone: userTimeZone || "unknown",
|
|
37
|
+
connection: connection?.effectiveType || "unknown",
|
|
38
|
+
deviceCategory,
|
|
39
|
+
href: window.location.href,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function usePackTrack() {
|
|
43
|
+
const [pathname, setPathname] = useState();
|
|
44
|
+
const analytics = async () => {
|
|
45
|
+
const browserData = getBrowserData();
|
|
46
|
+
if (pathname === browserData.pathname)
|
|
47
|
+
return;
|
|
48
|
+
setPathname(browserData.pathname);
|
|
49
|
+
try {
|
|
50
|
+
await fetch("/pack/track", {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify(getBrowserData()),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error("Error hit /pack/track: ", error.message);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
analytics();
|
|
64
|
+
}, [analytics]);
|
|
65
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"preview-provider.d.ts","sourceRoot":"","sources":["../../src/preview/preview-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAKnD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE;YACR,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACf,EAAE,mBAAmB,qBAqBrB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
|
+
import { usePackTrack } from "./pack-analytics";
|
|
2
3
|
import { PreviewContext } from "./preview-content";
|
|
3
4
|
import { PreviewToast } from "./preview-toast";
|
|
4
5
|
export function PreviewProvider({ children, isPreviewModeEnabled, siteSettings, customizerMeta, }) {
|
|
5
6
|
const [previewStorefrontSettings, setPreviewStorefrontSettings] = useState();
|
|
7
|
+
usePackTrack();
|
|
6
8
|
return (React.createElement(PreviewContext.Provider, { value: {
|
|
7
9
|
isPreview: !!isPreviewModeEnabled,
|
|
8
10
|
previewStorefrontSettings,
|