adopted-ember-addons / adopted-ember-addons/ember-metrics

option `hitCallback` doesn't work for google analytics.

未关闭
#102 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
367
派生
158
PR 合并指标
30 天内没有已合并 PR

描述

I'm trying to track outbound link navigations, and found that the way to do this with google analytics is to send an event and in the options set a `hitCallback` key to a function that will be called when the event has been received. This just flat out doesn't seem to work.. here's my component.js:

``` js
function exitToMessenger() {
console.log('redirecting to messenger.com!!')
window.location.href = 'https://www.messenger.com/t/heyimlea';
}

export default Ember.Component.extend({
metrics: Ember.inject.service(),
actions: {
sendToMessenger() {
console.log('send to messenger called')
var metrics = Ember.get(this, 'metrics')

var eventData = {
hitType: 'event',
eventCategory: 'Outbound Link',
eventAction: 'click',
eventLabel: 'Sent to messenger!',
eventValue: 'https://www.messenger.com/t/heyimlea'
};

// if (navigator.sendBeacon) {
// //https://github.com/googleanalytics/autotrack/blob/bcdd409c22430553a2a43275386877bf37600e68/lib/plugins/outbound-form-tracker.js#L77
// //https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
// eventData.transport = 'beacon'
// metrics.trackEvent(eventData)
// //metrics.trackPage({page: '/sent2messenger', title: "exiting to messenger" });
// //be sure analytics.js calls sendBeacon before exiting
// setTimeout(exitToMessenger, 4)
// } else {
eventData.hitCallback = exitToMessenger;
metrics.trackEvent(eventData)
// }
}
}
```

Searching something along the lines of 'analytics track outbound link' I find this help article from google analytics suggesting this method: https://support.google.com/analytics/answer/1136920?hl=en
Here's the docs on hitCallback: https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#hitcallback

I'd love to get this fixed and tested asap so that the ember community can have one comprehensive addon for analytics

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。