-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from timlrx/feat/analytics
Feat/analytics
- Loading branch information
Showing
9 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Script from 'next/script' | ||
|
||
import siteMetadata from '@/data/siteMetadata' | ||
|
||
const GAScript = () => { | ||
return ( | ||
<> | ||
<Script | ||
strategy="lazyOnload" | ||
src={`https://www.googletagmanager.com/gtag/js?id=${siteMetadata.analytics.googleAnalyticsId}`} | ||
/> | ||
|
||
<Script strategy="lazyOnload"> | ||
{` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${siteMetadata.analytics.googleAnalyticsId}', { | ||
page_path: window.location.pathname, | ||
}); | ||
`} | ||
</Script> | ||
</> | ||
) | ||
} | ||
|
||
export default GAScript | ||
|
||
// https://developers.google.com/analytics/devguides/collection/gtagjs/events | ||
export const logEvent = (action, category, label, value) => { | ||
window.gtag?.('event', action, { | ||
event_category: category, | ||
event_label: label, | ||
value: value, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Script from 'next/script' | ||
|
||
import siteMetadata from '@/data/siteMetadata' | ||
|
||
const PlausibleScript = () => { | ||
return ( | ||
<> | ||
<Script | ||
strategy="lazyOnload" | ||
data-domain={siteMetadata.analytics.plausibleDataDomain} | ||
src="https://plausible.io/js/plausible.js" | ||
/> | ||
<Script strategy="lazyOnload"> | ||
{` | ||
window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) } | ||
`} | ||
</Script> | ||
</> | ||
) | ||
} | ||
|
||
export default PlausibleScript | ||
|
||
// https://plausible.io/docs/custom-event-goals | ||
export const logEvent = (eventName, ...rest) => { | ||
return window.plausible?.(eventName, ...rest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Script from 'next/script' | ||
|
||
const SimpleAnalyticsScript = () => { | ||
return ( | ||
<> | ||
<Script strategy="lazyOnload"> | ||
{` | ||
window.sa_event=window.sa_event||function(){var a=[].slice.call(arguments);window.sa_event.q?window.sa_event.q.push(a):window.sa_event.q=[a]}; | ||
`} | ||
</Script> | ||
<Script strategy="lazyOnload" src="https://scripts.simpleanalyticscdn.com/latest.js" /> | ||
</> | ||
) | ||
} | ||
|
||
// https://docs.simpleanalytics.com/events | ||
export const logEvent = (eventName, callback) => { | ||
if (callback) { | ||
return window.sa_event?.(eventName, callback) | ||
} else { | ||
return window.sa_event?.(eventName) | ||
} | ||
} | ||
|
||
export default SimpleAnalyticsScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import GA from './GoogleAnalytics' | ||
import Plausible from './Plausible' | ||
import SimpleAnalytics from './SimpleAnalytics' | ||
import siteMetadata from '@/data/siteMetadata' | ||
|
||
const isProduction = process.env.NODE_ENV === 'production' | ||
|
||
const Analytics = () => { | ||
return ( | ||
<> | ||
{isProduction && siteMetadata.analytics.plausibleDataDomain && <Plausible />} | ||
{isProduction && siteMetadata.analytics.simpleAnalytics && <SimpleAnalytics />} | ||
{isProduction && siteMetadata.analytics.googleAnalyticsId && <GA />} | ||
</> | ||
) | ||
} | ||
|
||
export default Analytics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd59203
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: