Analytics
1.5K members online now
Understand information in your reports and troubleshoot reporting issues such as self-referrals, (not set) data, and inaccurate information
 
Guide Me
star_border
Reply

Report based on custom dimensions and custom metric with inconsistencies

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Hi,

 

This post is about Analytics and Tag Manager.

 

We have a website where the user can fill different forms for requesting different kind of products (forms create leads). We would like to have a report to know how many users start a form versus how many users complete the form.

 

All forms have different URLs. We know someone completes a form because they get to the Thank-You page. All forms use the same Thank-You page. User could complete 1 or more forms in same session.

 

We don’t have direct access to website code, so we are using Google Tag Manager.

 

This is what we have:

 

Analytics

- Dimension: Form Name (Scope: Hit)

- Dimension: Form ID (Scope: Hit)

- Metric: Form Started (Scope: Hit)

- Metric: Form Completed (Scope: Hit)

 

Tag Manager

- Trigger: Form Page

- Trigger: Thank-You Page

- Tag: Create Form Data (fires Form Page)

- Tag: Form Started (fires Form Page)

- Tag: Clear Form Data (fires Thank-You Page)

- Tag: Form Completed (fires Thank-You Page)

- Variable: FormName (JavaScript Variable)

- Variable: FormID (JavaScript Variable)

 

 

Tags Details:

 

* Tag: Create Form Data

    - Fires: Form Page

    - Type: Custom HTML

    - Tag firing priority: 9999

    - Cleanup Tag: Form Started

    - Pseudocode:

        1) Get FormName from page title. Keep the value in a global variable.

        2) Get FormID from URL. Keep the value in a global variable.

        3) Create cookie FormName

        4) Create cookie FormID

    - Code:

<script>

  var gtm = google_tag_manager[{{Container ID}}];

  try {

    var expirationTime = 60 * 60000; // Minutes in miliseconds

    var FormName = (document.getElementById("title").innerHTML);

    var FormID = (window.location.href).split('/').pop();

    var date = new Date();

    date.setTime(date.getTime() + expirationTime);

    var expirationTimeUTC = date.toUTCString();

    document.cookie = "FormName=" + FormName + "; expires=" + expirationTimeUTC + "; path=/";

    document.cookie = "FormID=" + FormID + "; expires=" + expirationTimeUTC + "; path=/";

    gtm.onHtmlSuccess({{HTML ID}}); 

} catch(e) {

    gtm.onHtmlFailure({{HTML ID}});

  }

</script>

 

* Tag: Form Started

    - Fires: Form Page

    - Type: Google Analytics

    - Custom Dimension: {1: FormName, 2: FormID}

    - Custom Metric: {1: 1} (Form Started)

 

* Tag: Clear Form Data

    - Fires: Thank-You Page

    - Type: Custom HTML

    - Tag firing priority: 9999

    - Cleanup Tag: Form Completed

    - Pseudocode:

        1) Get FormName from cookie. Keep the value in a global variable.

        2) Get FormID from cookie. Keep the value in a global variable.

        3) Delete cookie FormName

        4) Delete cookie FormID

    - Code:

<script>

  var gtm = google_tag_manager[{{Container ID}}];

  try {

    // Form Name

    var reN = new RegExp("FormName" + "=([^;]+)");

    var valueN = reN.exec(document.cookie);

    var FormName = (valueN !== null) ? unescape(valueN[1]) : '';

    document.cookie = "FormName=; expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/";

    // Form ID

    var reI = new RegExp("FormID" + "=([^;]+)");

    var valueI = reI.exec(document.cookie);

    var FormID = (valueI !== null) ? unescape(valueI[1]) : '';

    document.cookie = "FormID=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";

    gtm.onHtmlSuccess({{HTML ID}});

  } catch(e) {

    gtm.onHtmlFailure({{HTML ID}});

  }

</script>

 

* Tag: Form Completed

    - Fires: Thank-You Page

    - Type: Google Analytics

    - Custom Dimension: {1: FormName, 2: FormID}

    - Custom Metric: {2: 1} (Form Completed)

 

The ideal for us is to use “Form Name” for analytics custom report, but we had some issues with special characters, for that reason we added “Form ID” dimension.

 

The problem is that we are getting in some cases more “Form Completed” than “Form Started”, for example some day we had 14 “Form Started” vs 32 “Form Completed”. It doesn’t make sense.

 

I thought it could be people refreshing the Thank-You page, for that reason I implemented the code for clearing the cookies, but we still having similar inconsistencies. If I add Page dimension to the report, I found results where “Form ID = 1111” but “Page = /form/1076”, but it doesn’t make sense because I get the Form ID from the URL and send it to Analytics from a global variable (so, is not a cookie issue).

 

Thanks,

Re: Report based on custom dimensions and custom metric with inconsistencies

Explorer ✭ ✭ ☆
# 2
Explorer ✭ ✭ ☆
Hi Oscar,

Explanation that you provided is very thorough however could you please specify what is your desired outcome in terms of what you'd like to see in GA?

I'd like to help but I don't really grasp what it is that you try to accomplish.

Re: Report based on custom dimensions and custom metric with inconsistencies

[ Edited ]
Explorer ✭ ✭ ☆
# 3
Explorer ✭ ✭ ☆

I think that you may have overcomplicated it a little bit. Maybe you could try this approach instead:

1. Create variable FormID that returns and stores name of the id from URL. It should be relatively easy. Maybe you could even manage to do it without Custom HTML (using for example URL Fragment variable in GTM).

2. Create FormName variable (Lookup Table type) that will match IDs from FormID variable with respective titles

3. Create tag "Form Start" (Universal Analytics - Event type), trigger "Page View" type with condition "FormID" does not equal undefined. It will work for any URL that contains Form ID in URL. I assumed that FormID is present only in URL of your forms and not anywhere else.
Category: Form Start
Action: {{FormID}}
Label: {{FormName}}
Value: undefined
Set it to interactive.
Custom dimensions: {{FormName}}, {{FormID}}
Custom metric: Form Start

 

4. Create tag "Form Completed" (Universal Analytics - Event type), trigger "Page View" type with condition "URL" contains “Thank-You-Page”.
Category: Form Completed
Action: {{FormID}}
Label: {{FormName}}
Value: undefined
Set it to interactive.
Custom dimensions: {{FormName}}, {{FormID}}
Custom metric: Form Completed

 

Alternatively you may think of skipping using custom metrics and dimensions and check event report for Form Started and Form Completed events in the field “Unique Events”, this way you’ll eliminate artificially inflated conversions that your custom metrics and dimensions would produce (for example when people refresh form or Thank You Page and you use metrics and dimensions as a hit-based).

I think that should do what you’re trying to accomplish but without the need of creating and deleting cookies. If there is something wrong with this approach or you’d like some more help in setting this up then please let me know. I’d be glad to help.

Re: Report based on custom dimensions and custom metric with inconsistencies

Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆
Well, the issue was related with duplicate firing because I had Tag triggering + Cleanup firing. Now data is fine.

Re: Report based on custom dimensions and custom metric with inconsistencies

Explorer ✭ ✭ ☆
# 5
Explorer ✭ ✭ ☆
Hi,

It's good to hear that you managed to figure it out.