Add PostHog analytics

This commit is contained in:
Dhenain Ambroise
2022-04-03 17:31:11 +02:00
parent d98cf8e57b
commit 1d97e7dc40
6 changed files with 73 additions and 10 deletions

View File

@@ -6,8 +6,10 @@
*/
import { parsePageId } from 'notion-utils'
import { getSiteConfig, getEnv } from './get-config-value'
import { PageUrlOverridesMap, PageUrlOverridesInverseMap } from './types'
import posthog from 'posthog-js'
import { getEnv, getSiteConfig } from './get-config-value'
import { PageUrlOverridesInverseMap, PageUrlOverridesMap } from './types'
import Config = posthog.Config
export const rootNotionPageId: string = parsePageId(
getSiteConfig('rootNotionPageId'),
@@ -119,13 +121,23 @@ export const api = {
// ----------------------------------------------------------------------------
export const fathomId = isDev ? null : process.env.NEXT_PUBLIC_FATHOM_ID
export const fathomConfig = fathomId
? {
excludedDomains: ['localhost', 'localhost:3000']
}
: undefined
// PostHog automatically filters events coming from localhost
export const postHogId = process.env.NEXT_PUBLIC_POSTHOG_ID
export const postHogConfig: Config = {
// See https://posthog.com/docs/integrate/client/js#config
api_host: 'https://app.posthog.com',
loaded: (posthog_instance) => {
console.debug(`PostHog loaded`, posthog_instance)
// posthog_instance.identify(unique user id)
}
}
function cleanPageUrlMap(
pageUrlMap: PageUrlOverridesMap,
label: string