-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GoogleAnalytics): added react-ga (#68)
* feat(GoogleAnalytics): added react-ga * add events * add events --------- Co-authored-by: Daniel Dobkowski <[email protected]>
- Loading branch information
Showing
20 changed files
with
182 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
import { AnalyticsContext } from "./contexts/AnalyticsContext"; | ||
import { useGoogleAnalytics } from "./hooks"; | ||
|
||
export const AnalyticsWrapper: React.FC<PropsWithChildren> = ({ children }) => { | ||
const googleAnalytics = useGoogleAnalytics(); | ||
|
||
return <AnalyticsContext.Provider value={googleAnalytics}>{children}</AnalyticsContext.Provider>; | ||
}; |
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,4 @@ | ||
import React from "react"; | ||
import { UseGoogleAnalyticsReturn } from "../types"; | ||
|
||
export const AnalyticsContext = React.createContext({} as UseGoogleAnalyticsReturn); |
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 @@ | ||
export { useGoogleAnalytics } from "./useGoogleAnalytics"; |
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,29 @@ | ||
import { useState } from "react"; | ||
import ReactGA from "react-ga4"; | ||
import { GoogleAnalyticsEvent, UseGoogleAnalytics } from "../types"; | ||
|
||
export const useGoogleAnalytics: UseGoogleAnalytics = () => { | ||
const [trackingId, setTrackingId] = useState<string>(""); | ||
|
||
const init = (id: string) => { | ||
if (!id) return; | ||
ReactGA.initialize(id); | ||
setTrackingId(id); | ||
}; | ||
|
||
const sendEvent = (event: GoogleAnalyticsEvent) => { | ||
if (!trackingId) return; | ||
ReactGA.event(event); | ||
}; | ||
|
||
const send = (path: any) => { | ||
if (!trackingId) return; | ||
ReactGA.send(path); | ||
}; | ||
|
||
return { | ||
init, | ||
sendEvent, | ||
send, | ||
}; | ||
}; |
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 @@ | ||
export { AnalyticsWrapper } from "./AnalyticsWrapper"; |
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,14 @@ | ||
export interface UseGoogleAnalyticsReturn { | ||
init: (trackingId: string) => void; | ||
sendEvent: (event: GoogleAnalyticsEvent) => void; | ||
send: (path: any) => void; | ||
} | ||
|
||
export type UseGoogleAnalytics = () => UseGoogleAnalyticsReturn; | ||
|
||
export interface GoogleAnalyticsEvent { | ||
category: string; | ||
action: string; | ||
label?: string; | ||
value?: number; | ||
} |
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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ export const GET_SERVICE = gql` | |
theme | ||
defaultLocale | ||
localTimeZone | ||
googleTagId | ||
} | ||
title | ||
description | ||
|
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
Oops, something went wrong.