Skip to main content

Google Analytics Integration

The Google Analytics integration leverages the react-ga package, enabling features like tracking page views, events, and conversions in your React application.

TitleGoogle Analytics
IDgoogle-analytics
IconGoogle Analytics
Brand color#E37400
Contrast color#fff
DescriptionWe use Google Analytics to improve your browsing experience.
Privacy policyhttps://policies.google.com/privacy?hl=en-US
WrapperComponent
Enabled by default⛔️

Configuration Options

  • trackingId: Your Google Analytics tracking ID

getGoogleAnalytics Function

The getGoogleAnalytics function retrieves the initialized instance of react-ga. This allows for direct interactions with Google Analytics tracking features within your application.

Example Usage with react-router

This example demonstrates how to use the getGoogleAnalytics function in conjunction with react-router to track page views:

import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { getGoogleAnalytics } from '@consent-manager/integration-google-analytics';

function App() {
const location = useLocation();
useEffect(() => {
const ReactGA = getGoogleAnalytics();
if (ReactGA) {
ReactGA.pageview(location.pathname + location.search);
}
}, [location]);

// Your application content
return (
// ...
);
}

export default App;