react-ga4 icon indicating copy to clipboard operation
react-ga4 copied to clipboard

Not a function for initialize, send, event

Open graevsky opened this issue 1 year ago • 0 comments

Had an issue with this code

import ReactGA from 'react-ga4';

export const initGA = () => {

    ReactGA.initialize('***');
};

export const logPageView = (page: string) => {
    ReactGA.send({ hitType: 'pageview', page });
};

export const logEvent = (category: string, action: string, label?: string) => {
    ReactGA.event({ category, action, label });
};

Where calling initGA, logPageView, logEvent from any components will cause Error: initialize, send, event are not functions.

Im using React: 18.3.1 React DOM: 18.3.1 react-ga4: 2.1.0 TypeScript: 5.6.3 Webpack/Esbuild: Esbuild

My solution was to use default. E.g. ReactGA.default.initialize('***');

Is there any solution without using default?

graevsky avatar Dec 01 '24 16:12 graevsky