简体   繁体   English

如何为与之前进行的相同调用/匹配的Google Analytics(分析)自定义维度添加代码,并添加一些自定义维度(需要花费一些时间来计算)

[英]How to add code for Google Analytics custom dimensions for the same call/hit made prior, with some custom dimensions ( which take time to calculate )

I have GA embedded on my website. 我的网站上嵌入了GA。 I know I can send some custom dimensions, using 我知道我可以使用发送一些自定义尺寸

var d1 = "valueForD1";
ga('set', 'dimension1', d1);
ga('send', 'pageview');

This is instantaneous. 这是瞬时的。

Other way to do this by Measurement Protocol API ( https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide ). Measurement Protocol API的其他实现方法( https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide )。

with this 有了这个

POST /collect HTTP/1.1
Host: www.google-analytics.com
payload_data

This hit is made(I make) when my server has completed some processing and calculated the custom dimension. 当我的服务器完成一些处理并计算了自定义维度后,就会产生此点击(我做出)。

But I need to add only "dimension1" to the original GA data already got sent (in normal GA execution) without ga('set','dimension1',d1). 但是,我只需要向已发送的原始GA数据中添加“ dimension1”(在常规GA执行中),而无需ga('set','dimension1',d1)。

My point here is that this custom dimension takes some time to get calculated on server end. 我的意思是,此自定义维度需要一些时间才能在服务器端进行计算。 How will I add this dimension to the GA normal hit? 如何将此维度添加到GA常规匹配中?

It depends. 这取决于。 If this is a session- or user scoped dimension it should be enough to send a hit (eg via the measurement protocol) with the same client id (within the session lifetime, for a session scoped dimension). 如果这是会话范围或用户范围的维度,则足以发送具有相同客户端ID的匹配(例如,通过测量协议)(在会话生存期内,对于会话范围的维度)。 Session scope and user scope retain only the last value per session/user in any case, so it's enough to add it once per session. 在任何情况下,会话作用域和用户作用域仅保留每个会话/用户的最后一个值,因此每个会话添加一次就足够了。

If this is a hit scoped dimension you are out of luck with a standard account. 如果这是命中范围内的维度,那么您没有标准帐户的运气。 In a GA 360 account you can add dimensions and metrics to existing hits via query time import . 在GA 360帐户中,您可以通过查询时间导入将维度和指标添加到现有匹配中。

TL:DR : Send the hit on the call back function of the async call to send the event. TL:DR:发送异步调用的回叫功能中的匹配项以发送事件。 As the example 举个例子

Hi 你好

The custom dimensions need to be attached to a hit (always to reach the platform). 自定义尺寸需要附加到匹配项上(始终到达平台)。

The best way to work with async CD is to send this via a event, and setting the scope to Session or User Level. 使用异步CD的最佳方法是通过事件发送,并将作用域设置为“会话”或“用户级别”。 (this overwrite the previous hit data). (这会覆盖之前的匹配数据)。 The cons is that some users will not have the CD because you can send the hit of the PV and later the CD. 缺点是某些用户没有CD,因为您可以发送PV的歌曲,然后再发送CD。

This is an example in code using the Ajax library to send the ip, (this is async too) 这是使用Ajax库发送ip的代码示例(也是异步的)

  $.ajax({ url:"https://api.ipify.org?format=json", success:function(data) { console.log(data.ip); ga('send','event' , 'label', 'category' , {'dimension1' : data.ip}); } }); 

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

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