We have lots of links on a landing page which are effectively to be tracked in Google ads as a conversion (outbound click). We're using the code below but clicks on the links aren't being registered in Google ads..
There is no further URL to call on hence "// window.location = url;"
function gtag_report_conversion(url) {
var callback = function () {
if (typeof(url) != 'undefined') {
// window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'AW-xxxxxxxxx',
'event_callback': callback
});
return false;
}
$(document).ready(function () {
$("#lp-id-10").click(function () {
gtag_report_conversion();
});
$(document).ready(function () {
$("#lp-id-11").click(function () {
gtag_report_conversion();
});
We've tried a few ways of coding this but our conversion point in Google ads is still marked as Unverified
Related
Has anyone managed to get the tracking of embedded YouTube video play/pause/ended working with the Monster Insights plugin for WordPress, or have an example where they have this working with Google universal.js? Please see below for the code I have so far. I have other GA Events being tracked successfully which are working fine, e.g. onclick="__gaTracker ('send', 'event', 'Mobile Call Button', 'call', 'mobile-call-button');"
<script>
// YouTube API
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_...";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// This code is called by the YouTube API to create the player object
function onYouTubeIframeAPIReady(event) {
player = new YT.Player('decisions', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
var pauseFlag = false;
function onPlayerReady(event) {
// do nothing, no tracking needed
}
function onPlayerStateChange(event) {
// track when user clicks to Play
if (event.data == YT.PlayerState.PLAYING) {
__gaTracker('send', 'event', 'Videos', 'Play', 'decisionsvideo');
pauseFlag = true;
}
// track when user clicks to Pause
if (event.data == YT.PlayerState.PAUSED && pauseFlag) {
__gaTracker('send', 'event', 'Videos', 'Pause', 'decisionsvideo');
pauseFlag = false;
}
// track when video ends
if (event.data == YT.PlayerState.ENDED) {
__gaTracker('send', 'event', 'Videos', 'Finished', 'decisionsvideo');
}
}
</script>
Here is my iron-router route
this.route("video",{
path:'/video/:_id/:slug',
waitOn: function() {
Session.set("currentTitle",this.params.slug);
Session.set("currentVideoId",this.params._id);
console.log("waitOn");
},
onBeforeAction: function () {
},
action:function(){
console.log("action");
this.render();
},
data:function(){
console.log("data");
var video= Videos.findOne({_id: this.params._id});
if(video){
console.log("set the url");
Session.set("currentVideoURL",video.videourl);
Session.set("thumb",video.thumbs);
}
return {
video:video
};
}
});
After the template rendered event I'm calling some meteor method and processing the result
Template.video.rendered=function(){
console.log("render event");
var id=Session.get("currentVideoURL");
Meteor.call("getdata",id,function(e,d){
//processing
});
};
and in my html, I'm displaying some relative videos, on click of those videos I want to open the same page with this video data
but the video data in router is resetting and the rendered event is not firing(I didn't seen render event in console),
I want the page to open as we are coming from another url, I want all the events to be fired.
How to acheive this?
I'm trying to use this technique http://www.bicobic.com/posts/BkFDo4CqcSnGcGtri to add the google analytics to Meteor, but it's not working (I already checked with the Google Analytics Debugger). And I'm trying with the Universal Analytics code.
Here is my code
<template name="ganalytics">
<div id="ganalytics">
</div>
</template>
Meteor.startup(function() {
isGanalyticsLoaded = false;
//a scriptloaderfunction
//if the script jsE1 loaded the callback is executed
myScriptLoader = function funcMyScriptLoader(jsEl, callback) {
if (window.attachEvent) {
// for IE (sometimes it doesn't send loaded event but only complete)
jsEl.onreadystatechange = function funcOnReadyStateChange() {
if (jsEl.readyState === 'complete') {
jsEl.onreadystatechange = "";
} else if (jsEl.readyState === 'loaded') {
jsEl.onreadystatechange = "";
}
if (typeof callback === 'function') {
callback();
}
};
} else {
// most browsers
jsEl.onload = function funcOnLoad () {
if (typeof callback === 'function') {
callback();
}
};
}
};
});
Template.ganalytics.rendered = function() {
if(!isGanalyticsLoaded) {
window['GoogleAnalyticsObject']='ga';
window['ga']=window['ga']||function(){
(window['ga'].q=window['ga'].q||[]).push(arguments)
}, window['ga'].l=1*new Date();
var myGAJs = document.createElement('script'),
s = document.getElementsByTagName('script')[0];
myGAJs.type ='text/javascript';
myGAJs.async = true;
myGAJs.src = '//www.google-analytics.com/analytics.js';
myScriptLoader(myGAJs, function funcEventLoaded() {
isGanalyticsLoaded = true;
ga('create', 'UA-XXXXXX', 'url');
ga('send', 'pageview');
});
s.parentNode.insertBefore(myGAJs, s);
}
};
<template name="layout">
<div>
{{yield}}
</div>
{{yield 'ganalytics'}}
</template>
What could be wrong with my code?
Thanks in advance.
The newer Google Analytics snippet doesn't seem to work in Meteor but putting this older, optimized style in the HEAD does:
var _gaq=[['_setAccount','UA-xxx'],['_setDomainName', 'example.com'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
You can also do this to log client-side errors to GA:
// log client-side errors to Google Analytics
window.onerror = function(message, file, line) {
_gaq.push(['_trackEvent', 'JS Error', file + ':' + line + '\n\n' + message]);
};
I have asked this question on the google forum for AngularJS and haven't heard about it until now. Can someone help me understand what is going on here?
I am trying to periodically refresh a resource and it doesn't seem to be working. I have tracked it until the fact that the promise has been obtained from $http service but the XHR request is never created and fired when the method is invoked in setTimeout. However, if I do the same without setTimeout everything seems to be working just fine.
Working JSFiddle: http://jsfiddle.net/hponnu/Z62QN/2/
window.root_module = angular.module("MyApp", ['ngResource']);
function MainController($scope, $resource) {
$scope.buttonClick = function () {
var res = $resource("http://www.google.com");
res.get({}, function (response) {
alert("response");
}, function (err) {
alert("error");
});
}
}
Broken JSFiddle: http://jsfiddle.net/hponnu/H8aEt/10/
window.root_module = angular.module("MyApp", ['ngResource']);
window.count = 0;
function MainController($scope, $resource) {
$scope.buttonClick = function () {
setTimeout(function () {
alert("timeout: " + window.count);
var res = $resource("http://www.google.com");
res.get({},
function (response) {
alert("response: " + window.count);
window.count++;
}, function (err) {
alert("error: " + window.count);
window.count++;
});
}, 1000);
}
}
As you will clearly see in the broken jsfiddle the error alert is not fired for the first request unless a click event is triggered by click on the button again. I have started noticing this from AngularJS 1.1.4
Any ideas/suggestions?
PS: https://groups.google.com/forum/#!topic/angular/t28mazamT0E is the link for the Google groups thread.
You should always use Angularjs's $timeout instead of setTimeout().
function MainController($scope, $resource, $timeout) {
$scope.buttonClick = function () {
$timeout(function () {
...
}, 1000);
}
}
I've been experimenting with auto generating events for google tag manager.
We have a script that we have used with traditional async analytics that generates onclick events for downloads, emails and external clicks.
I modified it to generate a GTM event instead of a standard analytics event as follows:
if (typeof jQuery != 'undefined') {
jQuery(document).ready(function($) {
var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined)
baseHref = jQuery('base').attr('href');
jQuery('a').each(function() {
var href = jQuery(this).attr('href');
if (href && (href.match(/^https?\:/i)) && (!href.match(document.domain))) {
jQuery(this).click(function() {
var extLink = href.replace(/^https?\:\/\//i, '');
dataLayer.push ({'eventCategory' : 'External', 'eventAction' : 'click', 'eventLabel': extLink, 'event' : 'autoevent'});
if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
setTimeout(function() { location.href = href; }, 200);
return false;
}
});
}
else if (href && href.match(/^mailto\:/i)) {
jQuery(this).click(function() {
var mailLink = href.replace(/^mailto\:/i, '');
dataLayer.push({'eventCategory' : 'Email', 'eventAction' : 'click', 'eventLabel': mailLink, 'event' : 'autoevent'});
});
}
else if (href && href.match(filetypes)) {
jQuery(this).click(function() {
var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
var filePath = href;
dataLayer.push({'eventCategory' : 'Download', 'eventAction' : 'click', 'eventLabel': filePath', 'event' : 'autoevent'});
if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
setTimeout(function() { location.href = baseHref + href; }, 200);
return false;
}
});
}
});
});
}
Inside GTM I would listen for an event called autoevent, which would generate an event tag with values for Category, Action and Label.
I have been experimenting with a wordpress site so far.
My first attempt had the above script declared in the head.
The GTM code was in the body, as required.
Using the GA debugger in chrome, I am getting a JS error Uncaught SyntaxError: Unexpected identifier
on the line that issues the dataLayer push.
My Javascript sux, so I took a guess and declared the dataLayer above the GTM code, and moved the auto generating script below the GTM code, so that the dataLayer would be fully declared.
Same error occurs.
Any suggestions?
You have an extra single quote on filePath:
dataLayer.push({'eventCategory' : 'Download', 'eventAction' : 'click', 'eventLabel': filePath', 'event' : 'autoevent'});