Skip to content

Commit b253822

Browse files
authored
Fix amplitude tracking (#355)
- Don't double count in dev - Don't warn about default tracking - Fix button click events
1 parent 57858b8 commit b253822

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pages/_app.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GrazProvider } from "graz";
33
import { AppProps } from "next/app";
44
import Script from "next/script";
55
import "nextra-theme-docs/style.css";
6-
import { ReactNode, useEffect, useState } from "react";
6+
import { ReactNode, useEffect, useState, useRef } from "react";
77
import { WagmiConfig, createConfig } from "wagmi";
88
import { arbitrum, avalanche, mainnet, sepolia } from "wagmi/chains";
99
import * as amplitude from "@amplitude/analytics-browser";
@@ -37,17 +37,21 @@ const config = createConfig(
3737

3838
export default function Nextra({ Component, pageProps }: NextraAppProps) {
3939
const [mounted, setMounted] = useState(false);
40+
const amplitudeInitialized = useRef(false);
4041

4142
useEffect(() => setMounted(true), []);
4243
useEffect(() => {
4344
TagManager.initialize(tagManagerArgs);
4445
}, []);
4546
useEffect(() => {
46-
if (AMPLITUDE_API_KEY) {
47-
amplitude.init(AMPLITUDE_API_KEY);
47+
if (AMPLITUDE_API_KEY && !amplitudeInitialized.current) {
4848
amplitude.add(autocapturePlugin());
49+
amplitude.init(AMPLITUDE_API_KEY, {
50+
defaultTracking: true,
51+
});
52+
amplitudeInitialized.current = true;
4953
}
50-
});
54+
}, []);
5155

5256
// Make the global context available to every page.
5357
return (

0 commit comments

Comments
 (0)