html - Google Analytics JavaScript onClick issues with 'if' statement for hostname -
so basic function works sending pageview, have onclick events setup in html not working within same function in javascript if hostname = 'mydomain.com'
.
javascript (works fine):
(function(w,d){ var hostname = w.location && w.location.hostname; if(hostname == 'mydomain.com'){ ga("create","ua-104xxxxxx-1",{name:"new"});ga("new.send","pageview"); }})(window,document);
if add function within function, onclick event not work pageview still does. there multiple domains , there more javascript file rest pertains different domains other countries, etc.
javascript (doesn't work fine):
(function(w,d){ var hostname = w.location && w.location.hostname; if(hostname == 'mydomain.com'){ ga("create","ua-104xxxxxx-1",{name:"new"});ga("new.send","pageview"); function myfunc() { ga('send', 'event', {'eventcategory': 'video','eventaction': 'click','eventlabel': 'experience video','transport': 'beacon'});} }})(window,document);
html:
<a class="video" data-embed-url="https://www.youtube.com/embed/_xxxxxxx" href="https://www.youtube.com/watch?v=_xxxxxx" onclick=myfunc() target="_blank"> </a> <span>experience video</span>
what doing wrong?
Comments
Post a Comment