In around August 2017, Google changed the tracking code from the "ga" format to a new "gtag" format.AlexFox wrote:Hi Dave, I love this set-up and I've tried to implement something similar but I seem to get an error after clicking Yes or No;Dave Lee wrote:...
I've completed all of the google analytic setup prerequisites and I'm using google analytic debugger so I can see it's functioning correctly in all other aspects..Code: Select all
Running command: ga("send", "event", "Feedback - Yes", "N/A", "http://mypage.com") Command ignored. Unknown target: undefined
Does your version of this still work? Has anyone else had a similar problem?
Thanks!
My example uses the older "ga" tracking code format. This is still supported by Google, so my original script still works - obviously only if you're using the "ga" format tracking code.
If you're just getting your GA tracking code now, it'll be provided in the new "gtag" format.
So if you're using "gtag", the script needs to send the event information using gtag() rather than ga().
Code: Select all
$(document).ready(function(){
/* -------------- Feedback -------------- */
/* Yes click */
$('.feedback-yes').click(function() {
/* fade out question, fade in thankyou message */
$('.feedback-question').fadeOut(function() {
$('.feedback-reason.yes-thanks').fadeIn();
});
/* ga('send', 'event', 'Feedback - Yes', 'N/A', location.href); */
gtag('event', 'N/A', {
'event_category': 'Feedback - Yes',
'event_label': location.href
});
});
/* No click */
$('.feedback-no').click(function() {
/* fade out question, fade in thankyou message */
$('.feedback-question').fadeOut(function() {
$('.feedback-reason.no').fadeIn();
});
});
/* No - response reasons */
$('.feedback-reason .option').change(function() {
/* if any options change, disable checkbox, record event, and fade in thankyou and email link */
$(this).attr('disabled', true);
if ($(this).is(':checked')) {
/* get the label text of the reason (option) text that's selected */
var reason = $(this).attr('data-analytics-label');
/* ga('send', 'event', 'Feedback - No', reason, location.href); */
gtag('event', reason, {
'event_category': 'Feedback - No',
'event_label': location.href
});
}
$('.feedback-reason.no-thanks').fadeIn();
});
});