要通过单击获取 GA 数据,您可以进行查询,使您能够将数据连接在一起。
首先,您需要在 GA 中准备数据。因此,对于您发送的每次点击,将一些散列值或 clientId + 一些时间戳添加到自定义维度中。这将使您能够加入每个查询结果。
例如(这就是我们在 Scitylana 的做法)下面的这个脚本挂钩到 GA 的跟踪脚本,并确保每个命中都包含一个键,以便以后拼接查询结果
<script>
var BindingsDimensionIndex = CUSTOM DIMENSION INDEX HERE;
var Version = 1;
function overrideBuildTask() {
var c = window[window['GoogleAnalyticsObject'] || 'ga'];
var d = c.getAll();
if (console) { console.log('Found ' + d.length + ' ga trackers') }
for (var i = 0; i < d.length; i++) {
var e = d[i]; var f = e.get('name');
if (console) { console.log(f + ' modified') }
var g = e.get('buildHitTask');
if (!e.buildHitTaskIsModified) {
e.set('buildHitTask', function(a) {
window['_sc_order'] = typeof window['_sc_order'] == 'undefined' ? 0 : window['_sc_order'] + 1;
var b = ['sl=' + Version, 'u=' + e.get('clientId'), 't=' + (new Date().getTime() + window['_sc_order'])].join('&');
a.set('dimension' + BindingsDimensionIndex, b);
g(a);
if (console) {
console.log(f + '.' + a.get('hitType') + '.set.customDimension' + BindingsDimensionIndex + ' = ' + b)
}
});
e.buildHitTaskIsModified = true
}
}
}
window.ga = window.ga || function() {
(ga.q = ga.q || []).push(arguments);
if (arguments[0] === 'create') { ga(overrideBuildTask) }
};
ga.l = +new Date();
</script>
当然,现在您需要编写一些脚本来连接您从 GA 中取出的所有结果。