|
4 | 4 | | window.dataLayer = window.dataLayer || []; |
5 | 5 | | function gtag(){dataLayer.push(arguments);} |
6 | 6 | | gtag('js', new Date()); |
7 | | -
|
| 7 | +| |
8 | 8 | | gtag('config', 'UA-121109725-1'); |
9 | 9 | |</script> |
| 10 | +| |
| 11 | +|<script> |
| 12 | +|// From: https://support.google.com/analytics/answer/7478520?hl=en |
| 13 | +|/** |
| 14 | +|* Function that registers a click on an outbound link in Analytics. |
| 15 | +|* This function takes a valid URL string as an argument, and uses that URL string |
| 16 | +|* as the event label. Setting the transport method to 'beacon' lets the hit be sent |
| 17 | +|* using 'navigator.sendBeacon' in browser that support it. |
| 18 | +|*/ |
| 19 | +|var getOutboundLink = function(urlOrEvent) { |
| 20 | +| let url; |
| 21 | +| let target; |
| 22 | +| if(typeof urlOrEvent === 'string') { |
| 23 | +| url = urlOrEvent; |
| 24 | +| } else { |
| 25 | +| let event = urlOrEvent || window.event; |
| 26 | +| let el = event.target || event.srcElement; |
| 27 | +| if(!el.href) el = el.parentNode; |
| 28 | +| url = el.href; |
| 29 | +| target = el.target; |
| 30 | +| } |
| 31 | +| //console.log(url); |
| 32 | +| //console.log(target); |
| 33 | +| if(window.google_tag_manager) { |
| 34 | +| gtag('event', 'click', { |
| 35 | +| 'event_category': 'outbound', |
| 36 | +| 'event_label': url, |
| 37 | +| 'transport_type': 'beacon', |
| 38 | +| 'event_callback': function() { |
| 39 | +| window.open(url, target); |
| 40 | +| //document.location = url; |
| 41 | +| } |
| 42 | +| }); |
| 43 | +| } else { |
| 44 | +| window.open(url, target); |
| 45 | +| } |
| 46 | +|} |
| 47 | +|</script> |
0 commit comments