Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not a function for initialize, send, event #91

Open
graevsky opened this issue Dec 1, 2024 · 0 comments
Open

Not a function for initialize, send, event #91

graevsky opened this issue Dec 1, 2024 · 0 comments

Comments

@graevsky
Copy link

graevsky commented Dec 1, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant