added ga switch on cookie options
This commit is contained in:
+33
-19
@@ -1,35 +1,49 @@
|
||||
import Document, { Html, Head, Main, NextScript } from "next/document";
|
||||
import SkipLink from "../components/skiplink";
|
||||
import { Tracking, TrackingNoScript } from "../components/tracking";
|
||||
//import basicAuthMiddleware from "nextjs-basic-auth-middleware";
|
||||
import basicAuthMiddleware from "nextjs-basic-auth-middleware";
|
||||
|
||||
class MyDocument extends Document {
|
||||
// static async getInitialProps(ctx) {
|
||||
// const initialProps = await Document.getInitialProps(ctx);
|
||||
// if (ctx.req && ctx.res) {
|
||||
// await basicAuthMiddleware(ctx.req, ctx.res, {
|
||||
// users: [
|
||||
// {
|
||||
// name: "rehab",
|
||||
// password: "preventTesting",
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
// }
|
||||
// return { ...initialProps };
|
||||
// }
|
||||
static async getInitialProps(ctx) {
|
||||
const initialProps = await Document.getInitialProps(ctx);
|
||||
|
||||
let useGATracking = false;
|
||||
|
||||
if (ctx.req && ctx.req.headers.cookie) {
|
||||
typeof ctx.req.cookies.CookiePolicy != "undefined"
|
||||
? JSON.parse(ctx.req.cookies.CookiePolicy).usage == "accepted"
|
||||
? (useGATracking = true)
|
||||
: (useGATracking = false)
|
||||
: (useGATracking = true);
|
||||
} else {
|
||||
useGATracking = false;
|
||||
}
|
||||
|
||||
// if (ctx.req && ctx.res) {
|
||||
// await basicAuthMiddleware(ctx.req, ctx.res, {
|
||||
// users: process.env.BASIC_AUTH_CREDENTIALS,
|
||||
// });
|
||||
// }
|
||||
|
||||
return { ...initialProps, useGATracking };
|
||||
}
|
||||
|
||||
render() {
|
||||
const googleTagManagerID = process.env.GOOGLE_TAG_MANAGER || null;
|
||||
|
||||
const { useGATracking } = this.props;
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head>
|
||||
<Tracking googleTagManagerID={googleTagManagerID} />
|
||||
{useGATracking && (
|
||||
<Tracking googleTagManagerID={googleTagManagerID} />
|
||||
)}
|
||||
</Head>
|
||||
<body className="js-enabled">
|
||||
<TrackingNoScript googleTagManagerID={googleTagManagerID} />
|
||||
|
||||
{useGATracking && (
|
||||
<TrackingNoScript
|
||||
googleTagManagerID={googleTagManagerID}
|
||||
/>
|
||||
)}
|
||||
{!process.browser && (
|
||||
<script>
|
||||
window.switchDomain = `{process.env.I18N_DOMAIN}`
|
||||
|
||||
Reference in New Issue
Block a user