Google analytics events triggered by form submission


#1

Hello

I have been trying to add GA event triggered when a form is filled on my landing page. The problem is that the form is not embeded, but rather a part of a landing page designed in Hubspot. I contacted the support and the told me, there is no way to do that, but it is possible when embeding the form on a separate website.

This got me thinking, what if I embed the code in the rich text module? Theretically this should work, according to HubSpot support, but I'm having trouble making it work.

I can embed my form using the code provided byy Hubspot (embed form) - it works fine

However, when I try to add the GA part, the form does not display at all :frowning:

What makes it more complicated, is that once I remove the css: "" bit, the form is displayed (with default styling thought), but the GA event is not triggered upon submission. My knowledge of scripts and or php is limitted, but I think I've tried many different solutions from the hubspot community - none of the work :frowning:

Can anyone advise?
P.S.: Naturally, I have GA tracking code in the header of the landing page. :slight_smile:


#2

Hi @b.sklodowski,

Can you send me a link to the page in question so that I can take a closer look? At a first glance, that appears like it should work.


#3

Hi Derek,

The original page has gone live and since then I had to stop my little experiments and publish the form without GA. However I published a sample page with identical code in the header as well as embeded form in the rich text module (which does not display, but the embeded code is visible once you view the page's source)

URL: https://i.pocketecg.com/test-for-google-analytics-purposes

Regards


#4

Hi @b.sklodowski,

Thanks for that. This is actually related to the way the default Rich Text module functions. Rich Text modules won't function if they have no content other than a script tag in the source code, since they're not exactly the same as a custom HTML/HubL module. It would be better to use a Custom HTML or Custom HubL module in place of a flex column and Rich Text module, if possible. If that's absolutely not possible, you could include an empty div (i.e. <div></div>) in the Rich Text module source code to bypass this limitation.