Skip to content

Commit cca301f

Browse files
committed
Add Google Tag Manager integration and enhance PDF download tracking
1 parent 0b381b5 commit cca301f

4 files changed

Lines changed: 36 additions & 10 deletions

File tree

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ await import("./src/env.js");
88
const config = {
99
swcMinify: false,
1010
images: {
11-
domains: ["res.cloudinary.com"],
11+
domains: ["res.cloudinary.com", "storage.googleapis.com"],
1212
},
1313
webpack: (config, options) => {
1414
config.resolve.alias.canvas = false;

src/app/layout.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,28 @@ export default function RootLayout({
101101
/>
102102
<head>
103103
<Script
104-
async
105-
src="https://www.googletagmanager.com/gtag/js?id=G-J5CD036GJP"
106-
></Script>
107-
<Script id="google-analytics">
108-
{`window.dataLayer = window.dataLayer || [];
109-
function gtag(){dataLayer.push(arguments);}
110-
gtag('js', new Date());
111-
gtag('config', 'G-J5CD036GJP');`}
112-
</Script>
104+
id="google-tag-manager"
105+
strategy="afterInteractive"
106+
dangerouslySetInnerHTML={{
107+
__html: `
108+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
109+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
110+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
111+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
112+
})(window,document,'script','dataLayer','GTM-P32GFLD5');
113+
`,
114+
}}
115+
/>
113116
</head>
114117
<body>
118+
<noscript>
119+
<iframe
120+
src={`https://www.googletagmanager.com/ns.html?id=GTM-P32GFLD5`}
121+
height="0"
122+
width="0"
123+
style={{display: 'none', visibility: 'hidden'}}
124+
/>
125+
</noscript>
115126
<ThemeProvider
116127
attribute="class"
117128
defaultTheme="dark"

src/components/pdfViewer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
106106
};
107107

108108
const downloadPDF = async () => {
109+
if(window.dataLayer){
110+
window.dataLayer.push({
111+
'event': 'pdf_download_start',
112+
'paper_title': name,
113+
'paper_url': url,
114+
});
115+
}
109116
const fileName = `${name}.pdf`;
110117
await downloadFile(url, fileName);
111118
};

src/global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type DataLayer = Array<Record<string, unknown>>;
2+
3+
interface Window {
4+
dataLayer: DataLayer;
5+
}
6+
7+
// eslint-disable-next-line no-var
8+
declare var dataLayer: DataLayer;

0 commit comments

Comments
 (0)