简体   繁体   English

如何从Google Analytics(分析)跟踪器获取电子商务交易ID

[英]How to get E-commerce transaction ID from Google Analytics tracker

I'd like to know how to get the E-commerce transaction ID from a Google Analytics tracker object. 我想知道如何从Google Analytics(分析)跟踪器对象获取电子商务交易ID。

I already found the tracker.get() method: https://developers.google.com/analytics/devguides/collection/analyticsjs/accessing-trackers 我已经找到tracker.get()方法: https : //developers.google.com/analytics/devguides/collection/analyticsjs/accessing-trackers

By using tracker.get('clientId') , I successfully obtained the client ID from the Analytics tracker object. 通过使用tracker.get('clientId') ,我成功地从Analytics跟踪器对象获得了客户端ID。

According to the Analytics debug log, there is some transaction data stored in the Analytics tracker object with 'ec:id' as the transaction ID field. 根据Analytics(分析)调试日志,Analytics跟踪器对象中存储了一些交易数据,其中以“ ec:id”作为交易ID字段。 I tried to obtain the value of this field by using tracker.get('ec:id') , but this didn't return any result. 我试图通过使用tracker.get('ec:id')获得该字段的值,但是没有返回任何结果。

Analytics调试日志

Inspect your tracker in the console. 在控制台中检查您的跟踪器。 The following checks the first tracker, for example: 例如,以下检查第一个跟踪器:

ga.getAll()[0];

Inspect the data field, then inspect the keys field. 检查data字段,然后检查keys字段。 It'll be an array of what you can pass to a tracker's .get() method. 这将是您可以传递给跟踪器的.get()方法的数组。

I suggest you try getting the _ti out of your tracker: 我建议您尝试使_ti脱离跟踪器:

ga.getAll()[0].get('_ti');

If it corresponds with the transaction ID, then I did not screw up. 如果它与交易ID相符,那么我没有搞砸。

You should be able to reference the parameter by itself by using the ampersand syntax. 您应该能够使用&语法单独引用参数。 Documentation 文献资料

Reference for field parameters 现场参数参考

So for your case: 因此,对于您的情况:

tracker.get('&ti')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM