fix: Improved GA4 integration
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable prefer-rest-params */
|
||||||
/* global ga */
|
/* global ga */
|
||||||
import { escape } from "lodash";
|
import { escape } from "lodash";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
@@ -22,6 +23,7 @@ const Analytics: React.FC = ({ children }) => {
|
|||||||
ga("create", env.GOOGLE_ANALYTICS_ID, "auto");
|
ga("create", env.GOOGLE_ANALYTICS_ID, "auto");
|
||||||
ga("send", "pageview");
|
ga("send", "pageview");
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
|
script.type = "text/javascript";
|
||||||
script.src = "https://www.google-analytics.com/analytics.js";
|
script.src = "https://www.google-analytics.com/analytics.js";
|
||||||
script.async = true;
|
script.async = true;
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ const Analytics: React.FC = ({ children }) => {
|
|||||||
ga("send", "event", "pwa", "install");
|
ga("send", "event", "pwa", "install");
|
||||||
});
|
});
|
||||||
|
|
||||||
document.body?.appendChild(script);
|
document.getElementsByTagName("head")[0]?.appendChild(script);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Google Analytics 4
|
// Google Analytics 4
|
||||||
@@ -42,16 +44,20 @@ const Analytics: React.FC = ({ children }) => {
|
|||||||
const measurementId = escape(env.analytics.settings?.measurementId);
|
const measurementId = escape(env.analytics.settings?.measurementId);
|
||||||
|
|
||||||
window.dataLayer = window.dataLayer || [];
|
window.dataLayer = window.dataLayer || [];
|
||||||
function gtag(...args: any[]) {
|
window.gtag = function () {
|
||||||
window.dataLayer.push(args);
|
window.dataLayer.push(arguments);
|
||||||
}
|
};
|
||||||
gtag("js", new Date());
|
window.gtag("js", new Date());
|
||||||
gtag("config", measurementId);
|
window.gtag("config", measurementId, {
|
||||||
|
allow_google_signals: false,
|
||||||
|
restricted_data_processing: true,
|
||||||
|
});
|
||||||
|
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
|
script.type = "text/javascript";
|
||||||
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
|
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
|
||||||
script.async = true;
|
script.async = true;
|
||||||
document.body?.appendChild(script);
|
document.getElementsByTagName("head")[0]?.appendChild(script);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
|
|||||||
1
app/typings/window.d.ts
vendored
1
app/typings/window.d.ts
vendored
@@ -1,6 +1,7 @@
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
dataLayer: any[];
|
dataLayer: any[];
|
||||||
|
gtag: (...args: any[]) => void;
|
||||||
|
|
||||||
DesktopBridge: {
|
DesktopBridge: {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user