-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: align plugins to new structure and integrate in docs
- Loading branch information
Showing
7 changed files
with
101 additions
and
13 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,38 @@ | ||
import { useEffect } from 'react' | ||
|
||
import { | ||
useMatomo, | ||
trackPageViewSPA, | ||
} from '@consent-manager/integration-matomo' | ||
import { useSegment } from '@consent-manager/integration-segment' | ||
import { useGoogleAnalytics } from '@consent-manager/integration-google-analytics' | ||
|
||
// Ensure we do this only once per runtime | ||
let trackedMatomo = false | ||
let trackedSegment = false | ||
let trackedGoogleAnalytics = false | ||
|
||
export const InitialPageViewTracker = () => { | ||
const { location } = window | ||
|
||
const matomo = useMatomo() | ||
useEffect(() => { | ||
if (matomo && !trackedMatomo) { | ||
trackPageViewSPA({ matomo, location }) | ||
trackedMatomo = true | ||
} | ||
}, [location, matomo]) | ||
|
||
const ReactGA = useGoogleAnalytics() | ||
useEffect(() => { | ||
if (ReactGA && ReactGA.pageview && !trackedGoogleAnalytics) { | ||
ReactGA.pageview(location.pathname + location.search) | ||
trackedGoogleAnalytics = true | ||
} | ||
}, [location, ReactGA]) | ||
|
||
// Segment automatically tracks page view | ||
// @todo how to avoid duplication? some frameworks execute route update hook on initial view, others not (and initial call might not be late enough!) | ||
|
||
return null | ||
} |
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