Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Add Google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Feb 21, 2021
1 parent 78243ba commit c6b0580
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function SEO({ description, title, image = null, slug = null }) {
const twitterHandle = 'amfoss_in';
const seoCardImagePath = image ? image : '/logos/amfoss_seo.png';
const metaDescription = description || siteDescription;
const GoogleAnalyticsID = 'UA-115377745-1';

return (
<Head>
Expand All @@ -32,6 +33,21 @@ export default function SEO({ description, title, image = null, slug = null }) {
<meta name="twitter:image" content={seoCardImagePath} />
<meta name="twitter:title" content={`${title} | ${siteTitle}`} />
<meta name="twitter:description" content={metaDescription} />
{GoogleAnalyticsID && (
<React.Fragment>
<script
rel="preconnect"
async
src={`https://www.googletagmanager.com/gtag/js?id=${GoogleAnalyticsID}`}
/>
<script
nonce="{GENERATED_NONCE}"
dangerouslySetInnerHTML={{
__html: `window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '${GoogleAnalyticsID}');`,
}}
/>
</React.Fragment>
)}
</Head>
);
}

0 comments on commit c6b0580

Please sign in to comment.