Skip to content

Not a function for initialize, send, event #91

@graevsky

Description

@graevsky

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions