Merged PR 607: added ga switch on cookie options

added ga switch on cookie options

Related work items: #6682
This commit is contained in:
Robert Bond
2021-11-12 11:42:54 +00:00
7 changed files with 71 additions and 24 deletions
+2 -1
View File
@@ -31,5 +31,6 @@ I18N_DOMAIN = "cymru.local"
GOOGLE_TAG_MANAGER = GTM-T78CBC3 GOOGLE_TAG_MANAGER = GTM-T78CBC3
SHOWLOGIN = "true" SHOWLOGIN = "false"
SHOWREPRESENTATIONS = "false" SHOWREPRESENTATIONS = "false"
BASIC_AUTH_CREDENTIALS = pinswg:password|pinswg2:password2
+2 -2
View File
@@ -215,7 +215,7 @@ const CaseSummary = (props) => {
</Link> </Link>
)} )}
<a {/* <a
onClick={() => { onClick={() => {
//spinnerState(); //spinnerState();
router.back(); router.back();
@@ -223,7 +223,7 @@ const CaseSummary = (props) => {
className="govuk-button govuk-button--secondary" className="govuk-button govuk-button--secondary"
> >
{t("case:summary-back-button-label")} {t("case:summary-back-button-label")}
</a> </a> */}
</div> </div>
</div> </div>
</div> </div>
+13 -2
View File
@@ -17,11 +17,22 @@ const CookieBanner = () => {
let expDate = new Date(now); let expDate = new Date(now);
expDate.setDate(now.getDate() + 365); expDate.setDate(now.getDate() + 365);
console.log(expDate);
cookie.set("planning_casework", true, { cookie.set("planning_casework", true, {
expires: expDate, expires: expDate,
}); });
let cookieStr = {
"essential": "accepted",
"usage": "accepted",
"communications": "accepted",
"settings": "accepted",
};
cookie.set("CookiePolicy", JSON.stringify(cookieStr).toString(), {
expires: expDate,
path: "/",
});
setBannerVisible(false); setBannerVisible(false);
}; };
+14
View File
@@ -30,9 +30,23 @@ const CookieManagementMain = (props) => {
cookie.set("CookiePolicy", JSON.stringify(values).toString(), { cookie.set("CookiePolicy", JSON.stringify(values).toString(), {
expires: expDate, expires: expDate,
path: "/",
}); });
function delete_cookie(name, path, domain) {
document.cookie =
name +
"=" +
(path ? ";path=" + path : "") +
(domain ? ";domain=" + domain : "") +
";expires=Thu, 01 Jan 1970 00:00:01 GMT";
}
usageState == "revoked" && delete_cookie("CookiePolicy", "/");
cookie.set("planning_casework", true, { cookie.set("planning_casework", true, {
expires: expDate, expires: expDate,
path: "/",
}); });
}; };
+6
View File
@@ -126,12 +126,18 @@ let Login = (props) => {
const onHandleSubmit = (values) => { const onHandleSubmit = (values) => {
//spinnerState(); //spinnerState();
let now = new Date();
let expDate = new Date(now);
expDate.setDate(now.getDate() + 0.41);
getLogin(values.loginUserID, values.loginUserPassword).then((data) => { getLogin(values.loginUserID, values.loginUserPassword).then((data) => {
data.value.length != 0 data.value.length != 0
? (setValidLoginID(true), ? (setValidLoginID(true),
setLoggedInUserId(data.value[0].contactid), setLoggedInUserId(data.value[0].contactid),
setCookie(null, "pinsUser", data.value[0].contactid, { setCookie(null, "pinsUser", data.value[0].contactid, {
path: "/", path: "/",
expires: expDate,
}), }),
// spinnerState(), // spinnerState(),
router.replace({ router.replace({
+1
View File
@@ -29,6 +29,7 @@
"next": "^11.0.1", "next": "^11.0.1",
"next-redux-wrapper": "^7.0.2", "next-redux-wrapper": "^7.0.2",
"next-translate": "^1.0.7", "next-translate": "^1.0.7",
"nextjs-basic-auth-middleware": "^0.2.1",
"nookies": "^2.5.2", "nookies": "^2.5.2",
"path": "^0.12.7", "path": "^0.12.7",
"pm2": "^5.1.0", "pm2": "^5.1.0",
+33 -19
View File
@@ -1,35 +1,49 @@
import Document, { Html, Head, Main, NextScript } from "next/document"; import Document, { Html, Head, Main, NextScript } from "next/document";
import SkipLink from "../components/skiplink"; import SkipLink from "../components/skiplink";
import { Tracking, TrackingNoScript } from "../components/tracking"; import { Tracking, TrackingNoScript } from "../components/tracking";
//import basicAuthMiddleware from "nextjs-basic-auth-middleware"; import basicAuthMiddleware from "nextjs-basic-auth-middleware";
class MyDocument extends Document { class MyDocument extends Document {
// static async getInitialProps(ctx) { static async getInitialProps(ctx) {
// const initialProps = await Document.getInitialProps(ctx); const initialProps = await Document.getInitialProps(ctx);
// if (ctx.req && ctx.res) {
// await basicAuthMiddleware(ctx.req, ctx.res, { let useGATracking = false;
// users: [
// { if (ctx.req && ctx.req.headers.cookie) {
// name: "rehab", typeof ctx.req.cookies.CookiePolicy != "undefined"
// password: "preventTesting", ? JSON.parse(ctx.req.cookies.CookiePolicy).usage == "accepted"
// }, ? (useGATracking = true)
// ], : (useGATracking = false)
// }); : (useGATracking = true);
// } } else {
// return { ...initialProps }; useGATracking = false;
// } }
// if (ctx.req && ctx.res) {
// await basicAuthMiddleware(ctx.req, ctx.res, {
// users: process.env.BASIC_AUTH_CREDENTIALS,
// });
// }
return { ...initialProps, useGATracking };
}
render() { render() {
const googleTagManagerID = process.env.GOOGLE_TAG_MANAGER || null; const googleTagManagerID = process.env.GOOGLE_TAG_MANAGER || null;
const { useGATracking } = this.props;
return ( return (
<Html lang="en"> <Html lang="en">
<Head> <Head>
<Tracking googleTagManagerID={googleTagManagerID} /> {useGATracking && (
<Tracking googleTagManagerID={googleTagManagerID} />
)}
</Head> </Head>
<body className="js-enabled"> <body className="js-enabled">
<TrackingNoScript googleTagManagerID={googleTagManagerID} /> {useGATracking && (
<TrackingNoScript
googleTagManagerID={googleTagManagerID}
/>
)}
{!process.browser && ( {!process.browser && (
<script> <script>
window.switchDomain = `{process.env.I18N_DOMAIN}` window.switchDomain = `{process.env.I18N_DOMAIN}`