Skip to content

Commit 51e860e

Browse files
use new google scripts
1 parent 5b55161 commit 51e860e

File tree

13 files changed

+42
-232
lines changed

13 files changed

+42
-232
lines changed

pages/_app.tsx

+6-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import "../src/styles/main.scss";
55
import Head from "next/head";
66
import { useForm, FormProvider } from "react-hook-form";
77
import isEmpty from "lodash/isEmpty";
8-
import gaUtils, { getGoogleGACode } from "../src/externals/gaUtils";
98
import {
109
FormDataContextProvider,
1110
formInitialState,
@@ -38,13 +37,6 @@ function isServerRendered(): boolean {
3837

3938
// Get the Google Analytics code for the HTML snippet below.
4039
const isProduction = appConfig.nodeEnv === "production";
41-
const gaCode = getGoogleGACode(isProduction);
42-
// Set up Google Analytics if it isn't already. There's an HTML snippet in the
43-
// DOM below that initializes GA. If it fails, this tries again. The HTML
44-
// snippet is better since it works without javascript.
45-
if (!isServerRendered()) {
46-
gaUtils.setupAnalytics(isProduction);
47-
}
4840

4941
function MyApp({ Component, pageProps }: MyAppProps) {
5042
const router = useRouter();
@@ -67,7 +59,6 @@ function MyApp({ Component, pageProps }: MyAppProps) {
6759
useEffect(() => {
6860
const handleRouteChange = () => {
6961
aaUtils.pageViewEvent(window.location);
70-
gaUtils.trackPageview(window.location.pathname);
7162
};
7263
router.events.on("routeChangeComplete", () => handleRouteChange());
7364
return router.events.off("routeChangeComplete", () => handleRouteChange());
@@ -174,14 +165,12 @@ function MyApp({ Component, pageProps }: MyAppProps) {
174165
<script
175166
dangerouslySetInnerHTML={{
176167
__html: `
177-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
178-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
179-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
180-
})(document,'script','https://www.google-analytics.com/analytics.js','ga');
181-
182-
ga('create', '${gaCode}', 'auto');
183-
ga('send', 'pageview');
184-
`,
168+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
169+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
170+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
171+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
172+
})(window,document,'script','dataLayer','GTM-RKWC');
173+
`,
185174
}}
186175
/>
187176
{/* <!-- End Google Analytics --> */}

pages/_document.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class MyDocument extends Document {
1717
<script
1818
dangerouslySetInnerHTML={{
1919
__html: `
20+
window.gaDataLayer = []
2021
window.adobeDataLayer = [];
2122
const pageName = window.location.pathname.replace("/", "nypl|").replaceAll("/", "|") + window.location.search;
2223
window.adobeDataLayer.push({
@@ -29,6 +30,15 @@ class MyDocument extends Document {
2930
<script src={adobeAnalyticsTag} async></script>
3031
</Head>
3132
<body>
33+
<noscript>
34+
<iframe
35+
title="Google-tag-name"
36+
src="https://www.googletagmanager.com/ns.html?id=GTM-RKWC"
37+
height="0"
38+
width="0"
39+
style={{ display: "none", visibility: "hidden" }}
40+
></iframe>
41+
</noscript>
3242
{/* <!-- NYPL Header Script --> */}
3343
<div id="nypl-header"></div>
3444
<script src={dsHeader} async></script>

pages/congrats/index.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Heading } from "@nypl/design-system-react-components";
33
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
44
import { useTranslation } from "next-i18next";
5-
import React from "react";
5+
import React, { useEffect } from "react";
66
import { GetServerSideProps } from "next";
77

88
import ConfirmationGraphic from "../../src/components/ConfirmationGraphic";
@@ -19,6 +19,15 @@ function ConfirmationPage(): JSX.Element {
1919
// shouldn't happen.
2020
const ptype = formResults?.ptype || 7;
2121
const temporary = ptype === 7;
22+
useEffect(() => {
23+
if (state.formValues.username) {
24+
window.dataLayer = window.dataLayer || [];
25+
window.dataLayer.push({
26+
event: "library_card_submission",
27+
nypl_location: state.formValues.homeLibraryCode, // Example: "Simply E" This is just an example. This variable actually refers to the Preferred Location Name found on the current Adobe Data Layer
28+
});
29+
}
30+
}, []);
2231

2332
return (
2433
<div>

src/components/AccountFormContainer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import RoutingLinks from "../RoutingLinks.tsx";
1212
import AccountFormFields from "../AccountFormFields";
1313
import AcceptTermsFormFields from "../AcceptTermsFormFields";
1414
import { findLibraryCode } from "../../utils/formDataUtils";
15-
import { lcaEvents } from "../../externals/gaUtils";
15+
1616
import FormField from "../FormField";
1717
import { createQueryParams } from "../../utils/utils";
1818

@@ -39,7 +39,7 @@ const AccountFormContainer = () => {
3939
});
4040

4141
const nextUrl = `/review?${queryStr}`;
42-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
42+
4343
router.push(nextUrl);
4444
};
4545

src/components/AddressContainer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import Loader from "../Loader";
2222
import FormField from "../FormField";
2323
import { constructAddressType } from "../../utils/formDataUtils";
24-
import { lcaEvents } from "../../externals/gaUtils";
24+
2525
import { nyCounties, nyCities, createQueryParams } from "../../utils/utils";
2626
import useFormDataContext from "../../context/FormDataContext";
2727
import { commonAPIErrors } from "../../data/apiErrorMessageTranslations";
@@ -122,7 +122,7 @@ const AddressContainer: React.FC = () => {
122122
} else {
123123
nextUrl = `/address-verification?${queryStr}`;
124124
}
125-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
125+
126126
router.push(nextUrl);
127127
} else {
128128
setTimeout(() => {

src/components/AddressVerificationContainer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import useFormDataContext from "../../../src/context/FormDataContext";
1414
import { Address, AddressResponse } from "../../../src/interfaces";
1515
import RoutingLinks from "../../../src/components/RoutingLinks.tsx";
1616
import styles from "./AddressVerificationContainer.module.css";
17-
import { lcaEvents } from "../../externals/gaUtils";
17+
1818
import FormField from "../FormField";
1919
import { createQueryParams } from "../../utils/utils";
2020

@@ -131,7 +131,7 @@ function AddressVerificationContainer() {
131131

132132
// Finally, go to the acount page.
133133
const nextUrl = `/account?${queryStr}`;
134-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
134+
135135
router.push(nextUrl);
136136
};
137137

src/components/PersonalFormContainer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useRouter } from "next/router";
55
import useFormDataContext from "../../context/FormDataContext";
66
import PersonalFormFields from "../PersonalFormFields";
77
import RoutingLinks from "../RoutingLinks.tsx";
8-
import { lcaEvents } from "../../externals/gaUtils";
8+
99
import FormField from "../FormField";
1010
import {
1111
Form,
@@ -39,7 +39,7 @@ const PersonalFormContainer = () => {
3939
});
4040

4141
const nextUrl = `/location?${queryStr}`;
42-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
42+
4343
router.push(nextUrl);
4444
};
4545

src/components/ReviewFormContainer/index.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import styles from "./ReviewFormContainer.module.css";
2222
import AcceptTermsFormFields from "../AcceptTermsFormFields";
2323
import Loader from "../Loader";
2424
import FormField from "../FormField";
25-
import { lcaEvents } from "../../externals/gaUtils";
25+
2626
import aaUtils from "../../externals/aaUtils";
2727
import { createQueryParams } from "../../utils/utils";
2828
import useFormDataContext from "../../../src/context/FormDataContext";
@@ -90,7 +90,6 @@ function ReviewFormContainer() {
9090
buttonType="primary"
9191
id={`editSectionButton-${sectionName}`}
9292
onClick={() => {
93-
lcaEvents("Edit", sectionName);
9493
editSectionFlag(true);
9594
}}
9695
>
@@ -114,7 +113,6 @@ function ReviewFormContainer() {
114113
buttonType="primary"
115114
id="editAddressButton"
116115
onClick={() => {
117-
lcaEvents("Edit", "Location/Address");
118116
router.push(`/location?${queryStr}`);
119117
}}
120118
>
@@ -134,7 +132,6 @@ function ReviewFormContainer() {
134132
<Button
135133
buttonType="primary"
136134
id="submitSectionButton"
137-
onClick={() => {}}
138135
type="submit"
139136
>
140137
{t("button.submit")}
@@ -187,7 +184,7 @@ function ReviewFormContainer() {
187184
.then((response) => {
188185
// Update the global state with a successful form submission data.
189186
dispatch({ type: "SET_FORM_RESULTS", value: response.data });
190-
lcaEvents("Submit", "Submit");
187+
191188

192189
// Adobe Analytics
193190
aaUtils.trackApplicationSubmitEvent({

src/components/RoutingLinks.tsx/index.tsx

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import React from "react";
55
import Link from "next/link";
66
import { useTranslation } from "next-i18next";
77

8-
import { lcaEvents } from "../../externals/gaUtils";
98
import aaUtils from "../../externals/aaUtils";
109
import styles from "./RoutingLinks.module.css";
1110

@@ -41,14 +40,7 @@ function RoutingLinks({
4140
<div className={styles.container}>
4241
{previous?.url && (
4342
<Link href={previous.url}>
44-
<a
45-
className={styles.previous}
46-
onClick={() =>
47-
lcaEvents("Navigation", `Previous button to ${previous.url}`)
48-
}
49-
>
50-
{previousText}
51-
</a>
43+
<a className={styles.previous}>{previousText}</a>
5244
</Link>
5345
)}
5446
{!next?.submit ? (
@@ -58,7 +50,6 @@ function RoutingLinks({
5850
// Just track the "Get Started" or "Submit" clicks. Routing events
5951
// are tracked at the component level in each "onSubmit".
6052
onClick={() => {
61-
lcaEvents("Navigation", next.text);
6253
aaUtils.trackCtaEvent("Start Application", next.text, next.url);
6354
}}
6455
>

src/components/UsernameValidationFormFields/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { isAlphanumeric } from "validator";
1414
import FormField from "../FormField";
1515
import useFormDataContext from "../../context/FormDataContext";
1616
import styles from "./UsernameValidationFormFields.module.css";
17-
import { lcaEvents } from "../../externals/gaUtils";
17+
1818
import {
1919
apiErrorTranslations,
2020
commonAPIErrors,
@@ -72,7 +72,7 @@ const UsernameValidationForm = ({
7272
message = apiTranslations[message][lang] || message;
7373
}
7474

75-
lcaEvents("Availability Checker", "Username - available");
75+
7676
setUsernameIsAvailable({
7777
available: true,
7878
message,
@@ -94,7 +94,7 @@ const UsernameValidationForm = ({
9494
message = apiErrorTranslations[message][lang] || message;
9595
}
9696

97-
lcaEvents("Availability Checker", "Username - unavailable");
97+
9898
setUsernameIsAvailable({
9999
available: false,
100100
message,

src/components/WorkAddressContainer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from "../../interfaces";
2020
import Loader from "../Loader";
2121
import FormField from "../FormField";
22-
import { lcaEvents } from "../../externals/gaUtils";
22+
2323
import { constructAddressType } from "../../utils/formDataUtils";
2424
import useFormDataContext from "../../context/FormDataContext";
2525
import { createQueryParams } from "../../utils/utils";
@@ -115,7 +115,7 @@ const AddressContainer: React.FC = () => {
115115
} else {
116116
setIsLoading(false);
117117
nextUrl = `/address-verification?${queryStr}`;
118-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
118+
119119
router.push(nextUrl);
120120
}
121121
});

src/externals/gaUtils.test.ts

-95
This file was deleted.

0 commit comments

Comments
 (0)