Skip to content

Instantly share code, notes, and snippets.

@ScreamZ
Last active December 20, 2021 10:44
Show Gist options
  • Save ScreamZ/592886382e2bcf3c506e973d7bc2a106 to your computer and use it in GitHub Desktop.
Save ScreamZ/592886382e2bcf3c506e973d7bc2a106 to your computer and use it in GitHub Desktop.
Axeptio React
import { Router } from "next/router";
import { useEffect } from "react";
import ReactGA from "react-ga";
const Analytics: React.FC = () => {
useEffect(() => {
ReactGA.initialize(process.env.ANALYTICS_ID!);
Router.events.on("routeChangeComplete", ReactGA.pageview);
// @ts-ignore
window._axcb = window._axcb || [];
// @ts-ignore
window._axcb.push((axeptio) => {
axeptio.on("cookies:complete", (choices: any) => {
if (choices.google_analytics) {
ReactGA.set({ anonymizeIp: false });
} else {
ReactGA.set({ anonymizeIp: true });
}
});
});
return () => {
Router.events.off("routeChangeComplete", ReactGA.pageview);
};
}, []);
return null;
};
export default Analytics;
import { useEffect } from "react";
const AxeptioInjector = () => {
useEffect(() => {
const el = document.createElement("script");
el.setAttribute("src", "https://static.axept.io/sdk.js");
el.setAttribute("type", "text/javascript");
el.setAttribute("async", "true");
el.setAttribute("data-id", "5d40273ba87a1d369584df39");
if (document.body !== null) {
document.body.appendChild(el);
}
}, []);
return null;
};
export default AxeptioInjector;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment