I have problem with creating multiple conversions in google analytics without using Tag manager with multiple forms on the same site using Contact form 7 plugin for wordpress
.
In the header of the site I added code like this:
document.addEventListener( 'wpcf7mailsent', function( event ) {
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f712-o2'
});
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f1399-o1'
});
} );
<script>
wpcf7-f712-o2 and wpcf7-f1399-o1 are ID in DIVs that have been created by contact form 7 in html:
<div role="form" class="wpcf7" id="wpcf7-f712-o2" lang="pl-PL" dir="ltr">
<div class="screen-reader-response"><p role="status" aria-live="polite" aria-atomic="true"></p> <ul></ul></div>
<form action="/#wpcf7-f712-o2" method="post" class="wpcf7-form init" novalidate="novalidate" data-status="init">
....
And in google analytics conversion I have set TWO conversions:
Category: Contact_form
Action: submit
Label: wpcf7-f712-o2
and
Category: Contact_form
Action: submit
Label: wpcf7-f1399-o1
The problem is that if I test one of those forms, google analytics gives me information that conversion worked but from BOTH forms. While it should work only for ONE desired conversion, not both of them.
Is it possible to set this without using TAG manager?
2
Answers
I found solution at: https://agvento.by/en/web-development-en/how-to-create-and-edit-goals-in-google-analytics-for-contact-form-7/
I sent submit from one contact form and google analytics registered ONE sended form conversion.
In the first line of your code you create a listener for any event named
'wpcf7mailsent'
. So, when this event is fired, the callback, which has twoga()
calls, is executed. That means, no matter if you fire the'wpcf7mailsent'
event by clicking on one button or another, the callback that fires bothga()
is executed, thus sending two conversions to Google Analytics.If you are using Google Tag Manager, I would suggest to create two tags, one for each form. Make sure the trigger you attach to each tag corresponds to its own form, and not the other one. To distinguish which button was clicked, you can use the button’s text or the class name.
If you don’t want to use Google Tag Manager, just make sure that, in the callback, you fire the right
ga()
call. As in Tag Manager, you should be able to retrieve the ID, class name or whatever from the button clicked, in order to distinguish the form that has been submitted.