-
-
Notifications
You must be signed in to change notification settings - Fork 205
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 #161 from dassiorleando/feat/googleAnalytics
Allowed Google Analytics tracking
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 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
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,44 @@ | ||
/** | ||
* GA integration | ||
* https://github.com/vercel/next.js/tree/canary/examples/with-google-analytics | ||
*/ | ||
import { processEnv } from '@lib/processEnv' | ||
|
||
export const GA_TRACKING_ID = processEnv.gaMeasurementId | ||
|
||
/** | ||
* Custom event type for Google Analytics. | ||
* The action field is required. | ||
*/ | ||
export interface EventType { | ||
action: string, | ||
category?: string, | ||
label?: string, | ||
value?: string | ||
} | ||
|
||
/** | ||
* Triggers a GA page view event. | ||
* @link https://developers.google.com/analytics/devguides/collection/gtagjs/pages | ||
* | ||
* @param {string} url The URL to save the page view event with. | ||
*/ | ||
export const pageview = (url: string): void => { | ||
(window as any).gtag('config', GA_TRACKING_ID, { | ||
page_path: url, | ||
}) | ||
} | ||
|
||
/** | ||
* Pushes a custom GA event. | ||
* @link https://developers.google.com/analytics/devguides/collection/gtagjs/events | ||
* | ||
* @param {EventType} parameters The event parameters. | ||
*/ | ||
export const event = ({ action, category, label, value }: EventType): void => { | ||
(window as any).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
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
ab22281
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: