Some time ago I designed a website for a client, now he is doing AdWords and his ads
campaign manager asked me to place some Google Analitycs code in order to track form
submissions (“conversions” I guess)
This is the snippet I was asked to place, but I can´t find the proper way to do it Webflow
<script>
$(document).ready(function() {
// For single page apps or large sections, 30 seconds and it sends a msg to GA that's it's not a bounce
setTimeout(function(){_gaq.push(['_trackEvent', 'Control', 'Bounce Rate', ''])}, 30000);
$(document).on('click', '[data-gatrack]', function(e) {
var $link = $(this);
var trackData = $link.data('gatrack');
if (!trackData) { return; }
var trackParams = ['_trackEvent'].concat(trackData.split(','));
trackParams[3] = trackParams[3] || $link.text();
_gaq.push(trackParams);
});
});
</script>
A little question before I try this: In the code I was given I see an explicit reference to ‘centro-parque’, which I assume is the name the SEO manager gave to the conversion to track it´s “execution”…
Should I use that to replace some string in the code you posted?, I can´t tell if “Control”, “data-gatrack”, etc. are your equivalents to my event´s name or not.
Sorry, I have no prior experience with Analitycs. blush
I was using this code myself to pull out ids that were set within a CMS collection. So there where a bunch of links and my client wanted to track each link in GA. Sort of the same as what you wanted almost. I should have documented it more because I’d have to dig into to see what it all meant. Wish I had more free time…
I’m no Analytics expert myself.
I’d look up your push method in the GA docs and see what they expect to be passed. You can probably forget about all that link, trackData, TrackParams stuff. I don’t even remember what some of that was about now 1.5 years later. Reason to document better…
Anyway, I am still looking at this and this is what I´ve come up with so far:
I realized I should´t track using onClick or onSubmit, because that would also track forms that do not get submitted because of missing fields and the like.
So I placed this in webflow.js
// Submit form to Webflow
function submitWebflow(data) {
/*** GG Analytics below ***/
console.log('Exito. Push GGA event.');
dataLayer.push({'event': 'contacto-centro-del-parque'});
Using that the console flags a hit when the forms is sent but not when it fails… I didn´t test it thoroughly and I don´t even have access to the Analytics accountso I can´t see for myself whther it is tracking something or not.
Now I use this in my Footer Code. Which works with the Universal Tracking.
(…)
Hum, I could have sworn I replied to that post… It seems I didn´t. Anyway, that code looks much more clear to me. I am waiting for some feedback from the SEO manager about the chage I made to see if it works at all, and if it doesn´t I will try to implement your code.
Just realize that webflow.js gets wiped out on publish. I think webflow has some kind of webhooks now? I have to run.
I was aware that the file would get overriten, but not that it could have been deprecated… I will look into it more closely.