I'm using the new GA analytics.js to track my website, that triggers just fine. I'm trying to track a button for clicks (linking to an external website), making sure it opens in a new window so we have the time to track it.
<button class="knapp" id="b2" onclick="window.open('https://site.com');"
target="_blank" type="button">Text</button>
According to googles guidelines, I can now use JS to track this.
Hence, I updated the code to match my button ID and events, then placed it in my header.
<script type="text/javascript">
var downloadLink = document.getElementById('b2');
addListener(downloadLink, 'click', function() {
ga('send', 'event', 'External_link', 'click', 'KL-FB');
});
function addListener(element, type, callback) {
if (element.addEventListener) element.addEventListener(type, callback);
else if (element.attachEvent) element.attachEvent('on' + type, callback);
}
</script>
However, it doesn't trigger at all. I have a "normal" event tracker on a normal link that triggers just fine, but from what I can see in my console this doesn't even try.