Need help with google GG analytics code tracking form submittions

Hello

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

DataLayer.push ({‘event’: ‘contacto-parque’));

This should trigger when the form is submitted.

Any pointers on how to get it working?

Thanks in advance!

Muriel

https://preview.webflow.com/preview/centro-del-parque?preview=6b88bbcb79a4f9c84ab27b1f9c0f95a5

I use this in my footer code:

<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>

Hi!,

Thanks for the fast reply :slight_smile:

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

Thanks again.

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…

Yeah… I know that feeling :slight_smile:

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.

Does it look like it could work?

Thanks.
Muriel.

Now I use this in my Footer Code. Which works with the Universal Tracking. The other code worked with the Classic. Hope this is more clear.

Add a Custom a Attribute for your link within webflow with the following name and value:
data-gatrack = "YourEventCategory, YourEventAction"

Then in the footer code:

<script>
    $(document).ready(function() {      
      $(document).on('click', '[data-gatrack]', function(e) {
     
        var $link = $(this);
    	var commaSeperatedEventData = $link.data('gatrack');
    	var eventParams = commaSeperatedEventData.split(',');

    	if (!eventParams) { return; }

    	eventCategory = eventParams[0]
    	eventAction = eventParams[1]
    	eventValue = $link.text()

    	ga('send', {
      		hitType: 'event',
      		eventCategory: eventCategory,
      		eventAction: eventAction,
      		eventLabel: eventValue
    	});
          
      });
    });
    </script>
2 Likes

Just realize that webflow.js gets wiped out on publish. I think webflow has some kind of webhooks now? I have to run.

Hi Jim,

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.

Thanks for the heads up!!

Regards.