Form Tracking for Contact Form 7 on Google Tag Manager | BCS Form Tracking for Contact Form 7 on Google Tag Manager | BCSBCS

Form Tracking for Contact Form 7 on Google Tag Manager

Google Tag Manager BCS 2 days ago 49 Views 0 Comments

Update time: January 13, 2025

This article introduces how to track forms in Contact Form 7.

There are many ways to track Contact Form 7 form submissions:

  • Element visibility,:because if the Contact Form 7 form is successfully submitted, specific information will be displayed on the page, read more: 「GTM」Using Element Visibility for Form Submission Tracking
  • Dom eventsContact Form 7 provides several types of custom DOM events. You can utilize the events within your JavaScript code to run a function in a specific situation. Contact Form 7 provides the following DOM events:
    • wpcf7invalid — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because there are fields with invalid input.
    • wpcf7spam — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because a possible spam activity has been detected.
    • wpcf7mailsent — Fires when an Ajax form submission has completed successfully, and mail has been sent.
    • wpcf7mailfailed — Fires when an Ajax form submission has completed successfully, but it has failed in sending mail.
    • wpcf7submit — Fires when an Ajax form submission has completed successfully, regardless of other incidents.

 

Now we need to track the form submission in https://www.bbccss.com/contact-form-7

Next, let’s see how to implement form tracking through the DOM events provided by Contact Form 7:

Step 1 : Custom HTML to inject javascript

In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Custom HTML」,Name it “HTML – Contact Form 7 Listener”, and make the following settings: Form Tracking for Contact Form 7 on Google Tag Manager

Source Code:

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
 window.dataLayer.push({
 "event" : "cf7submission",
 "formId" : event.detail.contactFormId,
 "response" : event.detail.inputs
 })
}); 
</script>

In fact, it is the addEventListener method. Read more: GA4 Event Tracking Series ⑦ —— Custom Events (addEventListener Method)

Step 2 : Set Up the Variables

From the code, we can know that there are data layer variables formId and response in the data layer, which need to be obtained using data layer variables in GTM.

In GTM, click「 Variables」——「New」——「Choose a variable type to begin setup…」——「Data Layer Variable」, name it “dlv-formId”, and then set as follows:、

Form Tracking for Contact Form 7 on Google Tag Manager

 

Set the dlv-response in the same way.

Form Tracking for Contact Form 7 on Google Tag Manager

Step 3 : Set Up the Trigger

In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Custom Event」,Name it “Custom Event- CF7 Submit Form”, and make the following settings:

Form Tracking for Contact Form 7 on Google Tag Manager

From the code, we can know that the event is cf7submission, so the event name is set to cf7submission.

Step 4 : Set Up the Tags

In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Google Analytics: GA4 Event」,Name it “GA4-Event-CF7 Submit Form”, and make the following settings:Form Tracking for Contact Form 7 on Google Tag Manager

The event name is submit_form_cf7

Step 5 : Preview and Publish

Next is preview debugging.

Form Tracking for Contact Form 7 on Google Tag Manager

Tags is triggered and can be published.

Read More:

Step 6 : Custom Definitions

The next step is to register event parameters form_id, if you want to use it in GA4, you need to register it in the Custom definitions of GA4.

In GA4,click「Admin」——「Custom definitions」——「Create custom dimension」, then do the following configuration:

Form Tracking for Contact Form 7 on Google Tag Manager

The event parameter response is in Json format and cannot be directly registered as a custom dimension. It contains PII information and is not recommended to be sent to GA4.

Step 7 : Verify Data in Reports

Generally, after 24 hours, we can see the data in GA4, such as:

Form Tracking for Contact Form 7 on Google Tag Manager

 


If you don't understand, You can leave a comment below.
Like (0)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website