-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plausible analytics integration
- Loading branch information
Showing
6 changed files
with
63 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
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,43 @@ | ||
import Plausible, { type EventOptions, type PlausibleOptions } from "plausible-tracker"; | ||
|
||
// Add all custom events/goals here. | ||
export type PlausibleEvents = "pageview"; | ||
|
||
/** | ||
* Plausible Analytics - https://plausible.io. | ||
* | ||
* Enable and configure env in `/bootstrap.cjs`. | ||
*/ | ||
export const plausible = Plausible({ | ||
domain: env.plausible.domain || location.hostname, | ||
apiHost: env.plausible.apiHost || "https://plausible.io", | ||
hashMode: false, | ||
trackLocalhost: true | ||
}); | ||
|
||
export const trackEvent = ( | ||
eventName: PlausibleEvents, | ||
options?: EventOptions, | ||
eventData?: PlausibleOptions | ||
) => { | ||
if (!env.plausible.enable) return; | ||
plausible.trackEvent(eventName, options, eventData); | ||
}; | ||
|
||
export const enableAutoPageviews = () => { | ||
if (!env.plausible.enable) return; | ||
plausible.enableAutoPageviews(); | ||
}; | ||
|
||
export const enableAutoOutboundTracking = ( | ||
targetNode?: (Node & ParentNode) | undefined, | ||
observerInit?: MutationObserverInit | undefined | ||
) => { | ||
if (!env.plausible.enable) return; | ||
plausible.enableAutoOutboundTracking(targetNode, observerInit); | ||
}; | ||
|
||
export const plausibleBootstrap = () => { | ||
enableAutoPageviews(); | ||
enableAutoOutboundTracking(); | ||
}; |
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