You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
functionexitToMessenger(){console.log('redirecting to messenger.com!!')window.location.href='https://www.messenger.com/t/heyimlea';}exportdefaultEmber.Component.extend({metrics: Ember.inject.service(),actions: {sendToMessenger(){console.log('send to messenger called')varmetrics=Ember.get(this,'metrics')vareventData={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)// }}}
Also I think it'd be good to take whatever my solution ends up being and add it to an #Extra Examples section around the bottom of the readme (figuring out the eventCategory, eventAction, etc keys was a little tricky)
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: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
The text was updated successfully, but these errors were encountered: