analytics icon indicating copy to clipboard operation
analytics copied to clipboard

HTML integration does not recognize Analytics.page analytics.track

Open daneFFW opened this issue 1 year ago • 2 comments

I tried using the HTML demo here https://analytics-html-example.netlify.app/ but get errors in the console

(index):57 Uncaught TypeError: Cannot read properties of undefined (reading 'page') at pageView ((index):57:18) at HTMLButtonElement.onclick ((index):40:34)

24-04-26-1053

I am also getting similar errors on my test site running the html version. https://verceltest-iota-jet.vercel.app/index-DW.html

24-04-26-1055

daneFFW avatar Apr 26 '24 18:04 daneFFW

That demo is pretty old running the now dead google analytics v3.

Try with the latest version of Google analytics (totally different product sigh)

DavidWells avatar Apr 30 '24 00:04 DavidWells

Actually, https://unpkg.com/@analytics/google-analytics/dist/@analytics/google-analytics.min.js is new GA4.

Demo is outdated. Try the below code

<script src="https://unpkg.com/analytics/dist/analytics.min.js"></script>
<script src="https://unpkg.com/@analytics/google-analytics/dist/@analytics/google-analytics.min.js"></script>
<script type="text/javascript">
      /* Initialize analytics */
      var Analytics = _analytics.init({
        app: 'analytics-html-demo',
        debug: true,
        plugins: [
          // attach google analytics plugin
          analyticsGa({
            measurementIds: ['G-abc123']
          })
          // ... add any other third party analytics plugins
        ]
      })
      /* Fire page view */
      Analytics.page()
      /* Attaching a listener */
      Analytics.on('*', ({ payload }) => {
        console.log(`Event ${payload.type}`, payload)
      })
</script>

DavidWells avatar Apr 30 '24 00:04 DavidWells

@DavidWells Thanks!! Ill check it outl.

daneFFW avatar May 14 '24 18:05 daneFFW