-
Troubleshooting Webpack 5 errors when importing BetaAnalyticsDataClient from @google-analytics/data
Hey there, I’m working on a pretty cool project where I’m building a custom dashboard on an angular app and integrating Google Analytics 4 data using the Google Analytics Data API. I’m using the Node.JS client libraries from Google Analytics’ tutorial, which had been going pretty smoothly right up until I tried to insert the script into my Angular app. I was hoping for a smooth transfer, but instead, I encountered a pack of webpack 5 errors that rushed me on “ng serve”.
The real head-scratcher seems to be importing BetaAnalyticsDataClient. Every time I’ve tried importing it, nodemon has been throwing a fit and shooting out webpack errors. Now, my setup isn’t all that complicated – it essentially boils down to a three-component structure: there’s ‘site-statistics.component’ with its html and scss files, a script called ‘google-analytics.ts’ located in a sub-folder named “services”, and then there’s the ‘site-statistics.component’ importing a function from google-analytics.ts .
If this sounds like something to do with how I am using the Google Analytics Data API client library, can you tell me how I might be able to extract the response from the script and feed it to my angular component?
Just so you’re up to speed, let me share what I’ve already tried to resolve this:
- I’ve attempted adding a resolve.fallback on webpack.config.ts, but to no avail.
- I’ve attempted to set paths to each package on my TSCONFIG.JSON.
- I’ve even given react-scripts-rewired a go.
If you think that the problem lies in my usage of the Google Analytics Data API client library, could you guide me on how I can retrieve the response from the script and forward it to my Angular component?
Log in to reply.