react-ga4 icon indicating copy to clipboard operation
react-ga4 copied to clipboard

ReactGA.plugin.require("ecommerce");

Open mostlyharmless2024 opened this issue 2 years ago • 2 comments

Previously with react-ga we could use this code:

ReactGA.plugin.require("ecommerce"); 

ReactGA.plugin.execute("ecommerce", "addItem", {
  id,
  name,
  sku,
  category,
  quantity
});

ReactGA.plugin.execute("ecommerce", "addTransaction", {
  id,
  revenue
});
ReactGA.plugin.execute("ecommerce", "send");

Is there another way to pass data to Google Analytics Ecommerce with GA4 / react-ga4?

mostlyharmless2024 avatar Feb 10 '23 15:02 mostlyharmless2024

Using the conversion guide you should be able to use the gtag function:

import ReactGA from 'react-ga4'

// ...

ReactGA.gtag('event', 'purchase', {
  transaction_id: id,
  value: revenue,
  items: [
    {
      item_id: sku,
      item_name: name,
      item_category: category,
      quantity,
    }
  ]
})

blackjack26 avatar May 17 '23 03:05 blackjack26

Is there a specific variable type we need to pass on for value?

ivanMatijasTildeLoop avatar Jun 28 '23 07:06 ivanMatijasTildeLoop