Skip to content

Commit 85a3c19

Browse files
Merge pull request #266 from NYPL/RENO-4391/ga4
use new google scripts
2 parents 5b55161 + 3450663 commit 85a3c19

File tree

14 files changed

+38
-251
lines changed

14 files changed

+38
-251
lines changed

pages/_app.tsx

+6-28
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,
@@ -28,24 +27,6 @@ interface MyAppProps {
2827
pageProps: any;
2928
}
3029

31-
/**
32-
* Determines if we are running on server or in the client.
33-
* @return {boolean} true if running on server
34-
*/
35-
function isServerRendered(): boolean {
36-
return typeof window === "undefined";
37-
}
38-
39-
// Get the Google Analytics code for the HTML snippet below.
40-
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-
}
48-
4930
function MyApp({ Component, pageProps }: MyAppProps) {
5031
const router = useRouter();
5132
useRouterScroll({ top: 640 });
@@ -67,7 +48,6 @@ function MyApp({ Component, pageProps }: MyAppProps) {
6748
useEffect(() => {
6849
const handleRouteChange = () => {
6950
aaUtils.pageViewEvent(window.location);
70-
gaUtils.trackPageview(window.location.pathname);
7151
};
7252
router.events.on("routeChangeComplete", () => handleRouteChange());
7353
return router.events.off("routeChangeComplete", () => handleRouteChange());
@@ -174,14 +154,12 @@ function MyApp({ Component, pageProps }: MyAppProps) {
174154
<script
175155
dangerouslySetInnerHTML={{
176156
__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-
`,
157+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
158+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
159+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
160+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
161+
})(window,document,'script','dataLayer','GTM-RKWC');
162+
`,
185163
}}
186164
/>
187165
{/* <!-- End Google Analytics --> */}

pages/_document.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ class MyDocument extends Document {
2929
<script src={adobeAnalyticsTag} async></script>
3030
</Head>
3131
<body>
32+
<noscript>
33+
<iframe
34+
title="Google-tag-name"
35+
src="https://www.googletagmanager.com/ns.html?id=GTM-RKWC"
36+
height="0"
37+
width="0"
38+
style={{ display: "none", visibility: "hidden" }}
39+
></iframe>
40+
</noscript>
3241
{/* <!-- NYPL Header Script --> */}
3342
<div id="nypl-header"></div>
3443
<script src={dsHeader} async></script>

pages/congrats/index.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
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";
99
import useFormDataContext from "../../src/context/FormDataContext";
1010
import { FormResults } from "../../src/interfaces";
1111
import { homePageRedirect } from "../../src/utils/utils";
1212
import { cookieDomain } from "../../appConfig";
13+
import ilsLibraryList from "../../src/data/ilsLibraryList";
1314

1415
function ConfirmationPage(): JSX.Element {
1516
const { state } = useFormDataContext();
@@ -19,6 +20,15 @@ function ConfirmationPage(): JSX.Element {
1920
// shouldn't happen.
2021
const ptype = formResults?.ptype || 7;
2122
const temporary = ptype === 7;
23+
useEffect(() => {
24+
if (state.formValues.username) {
25+
(window as any).dataLayer = (window as any).dataLayer || [];
26+
(window as any).dataLayer.push({
27+
event: "library_card_submission",
28+
nypl_location: ilsLibraryList[state.formValues.homeLibraryCode],
29+
});
30+
}
31+
}, []);
2232

2333
return (
2434
<div>

src/components/AccountFormContainer/index.tsx

+1-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,6 @@ const AccountFormContainer = () => {
3939
});
4040

4141
const nextUrl = `/review?${queryStr}`;
42-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
4342
router.push(nextUrl);
4443
};
4544

src/components/AddressContainer/index.tsx

+1-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,6 @@ const AddressContainer: React.FC = () => {
122122
} else {
123123
nextUrl = `/address-verification?${queryStr}`;
124124
}
125-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
126125
router.push(nextUrl);
127126
} else {
128127
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/Banner/index.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@ interface BannerProps {
1313
* Simple component that returns the NYPL Design System's Hero component but
1414
* with other necessary components
1515
*/
16-
const Banner = ({
17-
fullImageSrc = defaultImageSrc,
18-
heroDescription = defaultDescription,
19-
}: BannerProps) => {
16+
const Banner = ({ fullImageSrc = defaultImageSrc }: BannerProps) => {
2017
const { t } = useTranslation("common");
2118
const h1Heading = (
2219
<Heading id="hero-banner" level="one" text={t("banner.title")} />
2320
);
24-
const subHeaderText = (
25-
<div className="hero__body-text">{heroDescription}</div>
26-
);
2721
return (
2822
<Hero
2923
backgroundColor="#333"

src/components/PersonalFormContainer/index.tsx

+1-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,6 @@ const PersonalFormContainer = () => {
3939
});
4040

4141
const nextUrl = `/location?${queryStr}`;
42-
lcaEvents("Navigation", `Next button to ${nextUrl}`);
4342
router.push(nextUrl);
4443
};
4544

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

+1-4
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,
@@ -71,8 +71,6 @@ const UsernameValidationForm = ({
7171
if (lang !== "en") {
7272
message = apiTranslations[message][lang] || message;
7373
}
74-
75-
lcaEvents("Availability Checker", "Username - available");
7674
setUsernameIsAvailable({
7775
available: true,
7876
message,
@@ -94,7 +92,6 @@ const UsernameValidationForm = ({
9492
message = apiErrorTranslations[message][lang] || message;
9593
}
9694

97-
lcaEvents("Availability Checker", "Username - unavailable");
9895
setUsernameIsAvailable({
9996
available: false,
10097
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
});

0 commit comments

Comments
 (0)