I don't like posting when a topic has been mentioned before but I can't find the answer and have spent about an hour trawling forums.
Okay, I didn't put the site together and I do SEO so my coding skills are pretty basic. I am trying to input Google Events Tracking for a client on a contact us form. I have found the code.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.ContactUs>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = "Master.cshtml";
}
<script>
document.getElementById("ContactUsNavLink").classList.add('active');
</script>
<body>
<div class="wrapper">
<div class="content container">
<div class="page-wrapper">
<header class="page-heading clearfix">
<h1 class="heading-title pull-left">Contact</h1>
<div class="breadcrumbs pull-right">
<ul class="breadcrumbs-list">
<li class="breadcrumbs-label">You are here:</li>
<li><a href="\home">Home</a><i class="fa fa-angle-right"></i></li>
<li class="current">Contact</li>
</ul>
</div>
</header>
<div class="page-content">
<div class="row">
<article class="contact-form col-lg-8 col-md-7 col-12 page-row">
<h3 class="title">Get in touch</h3>
<p>We’d love to hear from you. Please fill in required details including the date in which you want to book your vehicle for a Dinitrol Underseal (Please note to confirm your booking date a £50 deposit is required)</p>
<form action="https://formspree.io/[email protected]" method="POST">
<div class="form-group">
<label for="message">Message Type</label>
<select class="form-control" name="Message Type">
<option selected="selected" value="Contact Us">Contact Us</option>
<option value="Booking">Booking</option>
<option value="Book Inspection">Book Inspection</option>
</select>
</div>
<div class="form-group name">
<label for="name">Name</label>
<input id="name" type="text" class="form-control" placeholder="Enter your name" name="Name">
</div>
<div class="form-group email">
<label for="email">Email<span class="required">*</span></label>
<input id="email" type="email" class="form-control" placeholder="Enter your email" name="Email">
</div>
<div class="form-group phone">
<label for="phone">Phone</label>
<input id="phone" type="tel" class="form-control" placeholder="Enter your contact number" name="Phone">
</div>
<div class="form-group message">
<label for="message">Message<span class="required">*</span></label>
<textarea id="message" class="form-control" rows="6" placeholder="Enter your message here..." name="Message"></textarea>
</div>
<button type="submit" class="btn btn-theme">Send message</button>
</form>
</article>
I am pretty sure I should be putting the code here
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-96283580-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-96283580-1');
</script>
<script type="text/javascript">
//GA Event Tracker Script. Licensed under MIT. Free for any use by all. Written by Paul Seal from codeshare.co.uk
// Get the category, action and label from the element and send it to GA. The action is optional, because mostly it will be a click event.
var trackClickEvent = function () {
var eventCategory = this.getAttribute("data-event-category");
var eventAction = this.getAttribute("data-event-action");
var eventLabel = this.getAttribute("data-event-label");
var eventValue = this.getAttribute("data-event-value");
ga('send', 'event', eventCategory, (eventAction != undefined && eventAction != '' ? eventAction : 'click'), eventLabel, eventValue);
};
// Find all of the elements on the page which have the class 'ga-event'
var elementsToTrack = document.getElementsByClassName("ga-event");
// Add an event listener to each of the elements you found
var elementsToTrackLength = elementsToTrack.length;
for (var i = 0; i < elementsToTrackLength; i++) {
elementsToTrack[i].addEventListener('click', trackClickEvent, false);
}
</script>
I'm wondering if the Google analytics code has been added to your site? And if it has...Has it then been added correctly? I usually use a Chrome extension called GA debug, which you can find here https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna - It makes it possible to see if GA has been added properly to the site and it makes it possible to see if events are being captured when clicking on for instance a button, which is supposed to send some data to Google analytics - It does so by writing lines to the Chrome console log.
Also it might be a good idea to start out by checking if there is an error in the console log, which might be the reason the event is not visible in GA? - Also...Does GA detect clicks immediately these days? Or is there still a threshold of a certain amount of hours before it's possible to see the registered clicks? It's been a while since I have been testing GA setups. But I recall that once there was a delay in when you could actually see the events tracked in GA.
Google Analytics Event Tracking
Hi Guys,
I don't like posting when a topic has been mentioned before but I can't find the answer and have spent about an hour trawling forums.
Okay, I didn't put the site together and I do SEO so my coding skills are pretty basic. I am trying to input Google Events Tracking for a client on a contact us form. I have found the code.
I am pretty sure I should be putting the code here
Is this correct, have I missed something?
Regards Neil
Hi Neil,
You'll likely want to put that onClick event on the submit button as that's whats going to get triggered when the form submits.
Hope this helps!
Amir
Hi Amir/Everyone
Thanks so much for the help. I put the code in here:-
But can't see it analytics when I fill in a test enquiry in. Did I put it in the wrong place? This is using gtag.js. Am I being dumb here?
Regards Neil
Any help here please.
Hi Niel Have a look at this post I wrote about event tracking.
https://codeshare.co.uk/ga
Hi Paul,
Thank you so much for your help.
Here is what I put in
and here is what I put in on the button
And here is what Google analytics debugger said
Still not tracking, I know it's something simple, but still not tracking.
Regards Neil
Hi Neil
I'm wondering if the Google analytics code has been added to your site? And if it has...Has it then been added correctly? I usually use a Chrome extension called GA debug, which you can find here https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna - It makes it possible to see if GA has been added properly to the site and it makes it possible to see if events are being captured when clicking on for instance a button, which is supposed to send some data to Google analytics - It does so by writing lines to the Chrome console log.
Also it might be a good idea to start out by checking if there is an error in the console log, which might be the reason the event is not visible in GA? - Also...Does GA detect clicks immediately these days? Or is there still a threshold of a certain amount of hours before it's possible to see the registered clicks? It's been a while since I have been testing GA setups. But I recall that once there was a delay in when you could actually see the events tracked in GA.
Hope this helps!
/Jan
Hi Jan,
I put the Google Analytics debugger info in as above and included full code this time. Can you see anything I am missing
Regards Neil
is working on a reply...