|
|
@@ -1,69 +0,0 @@
|
|
|
-import posthog from 'posthog-js';
|
|
|
-import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
|
-
|
|
|
-const POSTHOG_KEY = 'phx_PEujL3LwMCfjwpnqyDtewBbgHZ9F4uoyrtCDjfNo43MHouY8';
|
|
|
-const POSTHOG_HOST = 'https://eu.i.posthog.com';
|
|
|
-
|
|
|
-let initialized = false;
|
|
|
-
|
|
|
-function initPostHog(): void {
|
|
|
- if (initialized || !ExecutionEnvironment.canUseDOM) return;
|
|
|
- initialized = true;
|
|
|
-
|
|
|
- posthog.init(POSTHOG_KEY, {
|
|
|
- api_host: POSTHOG_HOST,
|
|
|
- capture_pageview: true,
|
|
|
- capture_pageleave: true,
|
|
|
- person_profiles: 'identified_only',
|
|
|
- });
|
|
|
-
|
|
|
- document.addEventListener('click', (event) => {
|
|
|
- const target = event.target as HTMLElement | null;
|
|
|
- const anchor = target?.closest('a') as HTMLAnchorElement | null;
|
|
|
- if (!anchor) return;
|
|
|
-
|
|
|
- const href = anchor.getAttribute('href') ?? '';
|
|
|
- if (!href || href.startsWith('#')) return;
|
|
|
-
|
|
|
- const isExternal =
|
|
|
- /^https?:\/\//.test(href) && !href.includes('gazperi.com');
|
|
|
-
|
|
|
- if (isExternal) {
|
|
|
- posthog.capture('outbound_link_clicked', {
|
|
|
- href,
|
|
|
- text: anchor.textContent?.trim() ?? '',
|
|
|
- pathname: window.location.pathname,
|
|
|
- });
|
|
|
- } else if (
|
|
|
- href.startsWith('/') ||
|
|
|
- href.startsWith('./') ||
|
|
|
- href.startsWith('../')
|
|
|
- ) {
|
|
|
- posthog.capture('internal_nav_clicked', {
|
|
|
- to: href,
|
|
|
- text: anchor.textContent?.trim() ?? '',
|
|
|
- pathname: window.location.pathname,
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-export function onRouteDidUpdate({location, previousLocation}: {
|
|
|
- location: {pathname: string};
|
|
|
- previousLocation: {pathname: string} | null;
|
|
|
-}): void {
|
|
|
- if (!ExecutionEnvironment.canUseDOM) return;
|
|
|
- initPostHog();
|
|
|
-
|
|
|
- if (location.pathname.startsWith('/educacao')) {
|
|
|
- posthog.capture('docs_entry_visited', {
|
|
|
- slug: location.pathname,
|
|
|
- title: document.title,
|
|
|
- referrer_pathname: previousLocation?.pathname ?? null,
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-if (ExecutionEnvironment.canUseDOM) {
|
|
|
- initPostHog();
|
|
|
-}
|