Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+25
-12
@@ -1,4 +1,3 @@
|
||||
import platform from "platform";
|
||||
import { CookieCategory } from "~/application/cookies/CookieCategory";
|
||||
import CookieHelper from "./CookieHelper";
|
||||
import { AppRootData } from "../data/useRootData";
|
||||
@@ -14,7 +13,9 @@ type AnalyticsProps = {
|
||||
};
|
||||
|
||||
export async function addPageView({ url, rootData, route }: AnalyticsProps) {
|
||||
if (rootData.analytics && CookieHelper.hasConsent(rootData.userSession, CookieCategory.ANALYTICS)) {
|
||||
const analytics = rootData.analytics;
|
||||
const userAnalyticsId = analytics?.userAnalyticsId;
|
||||
if (analytics && userAnalyticsId && CookieHelper.hasConsent(rootData.userSession, CookieCategory.ANALYTICS)) {
|
||||
// console.log("[PAGE VIEW]", JSON.stringify({ url, analytics: rootData.analytics }));
|
||||
try {
|
||||
await fetch(new URL(apiPath("analytics/page-views", { mode: "host-aware" }), rootData.apiBaseUrl), {
|
||||
@@ -23,10 +24,7 @@ export async function addPageView({ url, rootData, route }: AnalyticsProps) {
|
||||
body: JSON.stringify({
|
||||
url,
|
||||
route,
|
||||
analytics: {
|
||||
...rootData.analytics,
|
||||
userAgent: getUserAgentDetails(),
|
||||
},
|
||||
analytics: createAnonymousAnalyticsPayload({ ...analytics, userAnalyticsId }, await getUserAgentDetails()),
|
||||
}),
|
||||
});
|
||||
} catch (e: any) {
|
||||
@@ -44,7 +42,9 @@ type EventProps = AnalyticsProps & {
|
||||
value: string;
|
||||
};
|
||||
export async function addEvent({ url, route, action, category, label, value, rootData }: EventProps) {
|
||||
if (rootData.analytics && CookieHelper.hasConsent(rootData.userSession, CookieCategory.ANALYTICS)) {
|
||||
const analytics = rootData.analytics;
|
||||
const userAnalyticsId = analytics?.userAnalyticsId;
|
||||
if (analytics && userAnalyticsId && CookieHelper.hasConsent(rootData.userSession, CookieCategory.ANALYTICS)) {
|
||||
// console.log("[EVENT]", JSON.stringify({ action, category, label, value, url, analytics: rootData.analytics }));
|
||||
try {
|
||||
await fetch(new URL(apiPath("analytics/events", { mode: "host-aware" }), rootData.apiBaseUrl), {
|
||||
@@ -57,10 +57,7 @@ export async function addEvent({ url, route, action, category, label, value, roo
|
||||
value,
|
||||
url,
|
||||
route,
|
||||
analytics: {
|
||||
...rootData.analytics,
|
||||
userAgent: getUserAgentDetails(),
|
||||
},
|
||||
analytics: createAnonymousAnalyticsPayload({ ...analytics, userAnalyticsId }, await getUserAgentDetails()),
|
||||
}),
|
||||
});
|
||||
} catch (e: any) {
|
||||
@@ -70,7 +67,23 @@ export async function addEvent({ url, route, action, category, label, value, roo
|
||||
}
|
||||
}
|
||||
|
||||
function getUserAgentDetails(userAgent?: string) {
|
||||
export function createAnonymousAnalyticsPayload(
|
||||
analytics: NonNullable<AppRootData["analytics"]> & { userAnalyticsId: string },
|
||||
userAgent: Awaited<ReturnType<typeof getUserAgentDetails>>
|
||||
) {
|
||||
return {
|
||||
userAnalyticsId: analytics.userAnalyticsId,
|
||||
...(analytics.referrer ? { referrer: analytics.referrer } : {}),
|
||||
...(analytics.region ? { region: analytics.region } : {}),
|
||||
userAgent,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getUserAgentDetails(userAgent?: string) {
|
||||
// `platform` is ~16 KiB minified and this helper is part of the root route.
|
||||
// Load the parser only after analytics consent caused an event to be sent,
|
||||
// keeping it out of every visitor's hydration graph.
|
||||
const { default: platform } = await import("platform");
|
||||
const deviceType = () => {
|
||||
if (!userAgent) {
|
||||
return undefined;
|
||||
|
||||
Reference in new issue
Block a user