Forminator and Events to track in Google Analytics
-
Hello,
I’m thinking about switching over to Forminator after using Contact Form 7. One thing that is a necessity for me is to be able to track form submissions in Google Analytics (as conversion goals) as events. Redirecting to a ‘Thank you’ page wouldn’t work for me.How can I do this?with Forminator, please?
Thank you,
Jan
-
Hello @mirackygmailcom ,
Our developer prepared a small snippet that can help to achieve that https://gist.github.com/wpmudev-sls/5fc34beaee5a34947cda67ccc6a56bff
Make sure to replace this part$tracking_id = 'UA-XXXXXXXX-X';
with your tracking ID.
Please note that using ?analytics.js? or ?Universal Analytics tag via Google Tag Manager? may require changes to the code.
kind regards,
KasiaHello Kasia,
thank you. I’d appreciate a bit more guidance. Where do I put this php file? What script do I need to place on a page with the contact form where I state the event details?Please, consider building this in your plugin. I’m sure many users will appreciate an easier way of tracking conversions.
Best regards,
JanHello @mirackygmailcom ,
I apologize for not giving more detailed instructions.
That code snippet is the only one that you need. There is no need for any additional scripts.
That script can be used as Must Use plugin.
As already mentioned, you can download the snippet here:
https://gist.github.com/wpmudev-sls/5fc34beaee5a34947cda67ccc6a56bffOnce downloaded, you can unzip it and update the following lines of code to match your Google Analytics property.
$tracking_id = 'UA-XXXXXXXX-X';
Then simply upload the wpmudev-forminator-google-analytics-events.php file to your site’s wp-content/mu-plugins directory. If directory do not exists, please create it.
If you need more help on installing this custom plugin please read our detailed guide here:
Installing WPMU DEV Plugins > Installing Mu-pluginsOur Beehive Analytics plugin will include an integration with Forminator in a future release.
kind regards,
KasiaThanks a lot, Kasia. I’ll give it a try.
Hi Kasia,
I completed all the steps above and see the snippet as Must-use plugin in the administration.With Contact Form 7, I used to have this piece of Javascript on the page with the contact form.
<script type="text/JavaScript"> document.addEventListener( 'wpcf7submit', function( event ) { gtag('send', 'event', 'Tour', 'Send Booking', '', 100); fbq('track', 'Purchase', {currency: 'CZK', value: 100); }, false ); </script>
It was for both Google Analytics and Facebook Pixel.
How do I modify it for Forminator events for both Analytics and Facebook Pixel, please?
Have a nice weekend,
Jan-
This reply was modified 4 years, 10 months ago by
Jan Mi?acky.
Hello @mirackygmailcom ,
We have updated code to include FB pixel.
$facebook_pixel = 'XXXXXXXX';
is the new parameter to set.fbq( 'track', 'Purchase', { currency: "USD", value: 30.00 } );
it is the event you need to modify according to your needs.
kind regards,
KasiaHello Kasia,
thank you. I updated the PHP file and added the FB pixel code.In my last comment, I mentioned a script code that I used to add on the page with CF7 form. In addEventListener, there is ‘wpcf7submit’. I tried to replace it with ‘forminator:form:submit:success’.
What I see in my Google Analytics is that after form submission, it records the event but it doesn’t pass on the Event Category, Action and Label name. In Analytics, it only shows are ‘action’, ‘label’, etc.
I need for every form to show in Analytics the parameters I set in addEventListener – for example, ‘Tour’, ‘Send Booking’, etc.
I’m clearly missing something obvious and I hope you can point me in the right direction.
Best,
JanI hope you’re well today!
in the shared code there’s this line:
gtag( 'event', 'action', { 'event_category': 'category', 'event_label': 'label','value': 'value' } );
If I correctly understand your needs, you should be able to modify that like, for example,
gtag( 'event', 'action', { 'event_category': 'booking', 'event_label': 'summer tour','value': '100' } );
Best regards,
AdamHi Adam,
I’m good, thank you. I hope that you, too.I understand your point. However, I have multiple forms (eg. tours in different cities) and I need to customize Category, Label, etc. for each one. Having this hardcoded is not very convenient.
To show an example how I used to use it with CF7 is mentioned in this post above. On a page where I had the form, I included that script in which I specified what should be sent to Analytics as Category, Label, etc.
This has allowed me to easily customize it for every form and get more detailed data to work with in Analytics.
I was wondering whether I could do the same with Forminator as it doesn’t seem very difficult to make it work.
If it’s still not 100% clear, let me know and I’m very happy to explain it better.
Best regards,
JanHello @mirackygmailcom
I hope all is well!
Our developers had updated the snippet!
A
var form_id
was added in the JavaScript code so you could use if-else statements. If a form matches an ID then you can do all the requests you need.Please download the code below:
https://gist.github.com/wpmudev-sls/5fc34beaee5a34947cda67ccc6a56bffHave a good day!
Kind regards,
NastiaHi Nastia,
thank you very much for this. I tried it and it tracks my custom labels to the given forms.However, it seems to submit the events twice – once with my custom labels and second just generic ones like before (‘label’, ‘category’, etc.).
It seems that we need to add a rule that if the form id matches in the first place, it should not send the second generic event.
Could you please look into it?
Best regards,
JanHello there @mirackygmailcom
I hope you’re doing well!
In our previous post, we provided you an updated snippet in which we added the variable of form’s ID.
Please use that, according to your needs. For example, if form ID is 100, do something else not.
Your request has evolved to a custom request which is beyond our support’s scope. Our snippet has rich comments to help you out but if still helped needed you can consult a developer.
Thank you,
Kind regards,
Nastia.Hello Nastia,
that’s fair enough. Thank you for your help, you and your team did a great job!Best regards,
JanI just ran across this topic and it’s super helpful! I’ve been migrating from Gravity Forms to Forminator and my SEO dept isn’t crazy about that, because of Forminator’s compatibility issues with GTM.
I’m looking to run that snippet on some sites, and am wondering: is it possible to execute it using something like Code Snippets? I already have that plugin installed for other tasks, and it would keep me from having to add another plugin.
Hey there @scocknation
Using such plugin instead of a MU plugin file shouldn’t make any difference. Just add whole gist in your custom snippet and keep in mind not having duplicate opening PHP tags at the very beginning:
<?php
Thank you,
Dimitris -
This reply was modified 4 years, 10 months ago by
- The topic ‘Forminator and Events to track in Google Analytics’ is closed to new replies.