使用包react-ga,如何要求具有多个跟踪器的电子商务插件?
有我的工作初始化代码:
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;
};
以及如何在特定的跟踪器上执行addTransaction?
ReactGA.plugin.execute(`ecommerce`, `addTransaction`, {
id: orderId,
affiliation: "Shop",
revenue: price
});
谢谢
答案 0 :(得分:0)
好的,我找到了一种实现方法:
要使用电子商务插件:
ReactGA.ga("trackerGlobal.require", "ecommerce");
要添加交易,请执行以下操作:
ReactGA.ga(`${trackerName}.ecommerce:addTransaction`, {
id: orderId,
affiliation: "Affiliation",
revenue: order.price
});