我正在使用react-ga,并且工作得很好。我可以调用事件并跟踪页面。
但Google Adwords中的转换脚本略有不同:
<script>
function gtag_report_conversion(url) {
var callback = function () {
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'AW-XXXX/XXXX',
'value': 140.0,
'currency': 'BRL',
'transaction_id': '',
'event_callback': callback
});
return false;
}
</script>使用React-GA,我可以像这样注册事件:
ReactGA.event({
category: "User",
action: "Click Whatsapp button",
value: 1,
});问题是对象没有"send_to“、"event_callback”、"currency“、"transaction_id”属性。
所以我必须使用ga对象来做这件事(我想)。我不知道ga对象和Google Adwords告诉我使用的gtag对象之间是否有区别。
我尝试注册转换,但什么也没有发生:
ReactGA.ga("event", "conversion", {
send_to: "AW-XXXX/XXXX",
value: 140.0,
currency: "BRL",
transaction_id: "",
});发布于 2020-10-30 07:33:18
在尝试了许多不同的方法之后,这才是真正解决这个问题的方法:
在public/index.html中添加标记,而不调用配置:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
</script>然后将此路由添加到所有路由之上和交换机组件之外:
// This will be called every time the location change
<Route
path="/"
render={({ location }) => {
window.gtag('config', 'UA-XXXXXXXXX', {
page_path: location.pathname + location.search,
});
}}
/>现在,您可以在任何位置使用带有所有参数的gtag对象:
window.gtag('event', 'purchase', {
send_to: 'AW-XXXX/XXXX',
value: order.orderTotal,
currency: 'BRL',
transaction_id: order.orderId,
shipping: parseFloat(order.shipping.price),
items: formatedItems,
});.https://stackoverflow.com/questions/64599106
复制相似问题