Ad
How To Use React.GA.plugin.require With Multiple Trackers
With the package react-ga, how to require the plugin ecommerce with multiple trackers ?
There is my working initialization code :
const initTracker = (trackerId, name) => ({
trackingId: trackerId,
gaOptions: { name }
});
const initializeGA = () => {
const trackers = [initTracker("UA-XXXXXXXX-1", "trackerGlobal")];
if (window.ga) {
const trackingId = ga.getAll()[0].get("trackingId");
trackers.push(initTracker(trackingId, "trackerSite"));
}
ReactGA.initialize(trackers, {
debug: true,
alwaysSendToDefaultTracker: false
});
ReactGA.plugin.require("trackerGlobal.ecommerce"); //Don't work
ReactGA.plugin.require("trackerSite.ecommerce"); // Don't work
return trackers;
};
And how to execute an addTransaction on a specific tracker ?
ReactGA.plugin.execute(`ecommerce`, `addTransaction`, {
id: orderId,
affiliation: "Shop",
revenue: price
});
Thanks,
Ad
Answer
Ok, I find a way to implement it :
To require the ecommerce plugin :
ReactGA.ga("trackerGlobal.require", "ecommerce");
To add a transaction:
ReactGA.ga(`${trackerName}.ecommerce:addTransaction`, {
id: orderId,
affiliation: "Affiliation",
revenue: order.price
});
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad