MauricioRobayo/nextjs-google-analytics

Can't send view_item, add_to_cart... etc ecommerce event.

akzone opened this issue · 7 comments

Hello is this package only works for basic event like page_view, scroll?

I tried to send ecommerce event but it's not working.

https://developers.google.com/analytics/devguides/collection/ga4/ecommerce

Thank you.

event("purchase", {
transaction_id: 1,
value: 99.99,
currency: "USD",
items: [] <--- array of items here
});

Yes I did but the event doesn't sent.

event("purchase", { transaction_id: 1, value: 99.99, currency: "USD", items: [] <--- array of items here });

Definitely working for me through many 1000's of transactions. Note, there is a delay before you will see these purchase. Can be 24 hours.

Thanks for the help, finally figured out that must add this line to send event

.env file
NEXT_PUBLIC_GA_MEASUREMENT_ID=xxxxx THIS WORK

_app.js
<GoogleAnalytics gaMeasurementId="xxxxx" /> THIS WON'T WORK

.env file
NEXT_PUBLIC_GA_MEASUREMENT_ID=xxxxx THIS WORK

_app.js
<GoogleAnalytics gaMeasurementId="xxxxx" /> THIS WON'T WORK

@akzone thanks for reporting this!

I've been looking into it as this should not be the expected behavior but could not find anything that might be causing this.

Do you have a repo where this is reproducible?

I created a test repo and it seems to be working fine while using the gaMeasurementId prop, I'm using the Google Analytics Debugger chrome extension:

// _app.ts
import type { AppProps } from "next/app";
import { GoogleAnalytics } from "nextjs-google-analytics";

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <GoogleAnalytics gaMeasurementId="xxxxxxx" />
      <Component {...pageProps} />
    </>
  );
}

Screenshot 2023-02-27 at 9 34 43 AM

ahhh, that might have been caused by the event requiring a gaMeasurementId, but that was recently removed:

#313

Would you mind updating to the latest version and testing it again?

ahhh, that might have been caused by the event requiring a gaMeasurementId, but that was recently removed:

#313

Would you mind updating to the latest version and testing it again?

Tested, it's okay now!

Thanks for the great work!