Basic Setup
This feature allows you to set up the Google Analytics tracking ID and anonymize IP addresses. The tracking ID is required to link your site to your Google Analytics account.
{
"plugins": [
[
"@docusaurus/plugin-google-gtag",
{
"trackingID": "YOUR_GOOGLE_ANALYTICS_TRACKING_ID",
"anonymizeIP": true
}
]
]
}
Custom Events
This feature allows you to track custom events such as button clicks. You can use the `useGtag` hook to send custom events to Google Analytics.
{
"plugins": [
[
"@docusaurus/plugin-google-gtag",
{
"trackingID": "YOUR_GOOGLE_ANALYTICS_TRACKING_ID",
"anonymizeIP": true
}
]
]
}
// In your React component
import React from 'react';
import { useGtag } from '@docusaurus/plugin-google-gtag';
const MyComponent = () => {
const gtag = useGtag();
const handleClick = () => {
gtag('event', 'click', {
event_category: 'button',
event_label: 'my_button'
});
};
return <button onClick={handleClick}>Click me</button>;
};
export default MyComponent;