Tracking Completed + Problematic Contact Forms in Analytics

In this article we’ll show you a basic method to track your form submission with emphasis into fields filled out, fields not filled and problematic fields all input into Google Analytics using event tracking. With this data you’ll be able to gather conclusions, fix errors and remove unneeded fields.

event tracking fields

Setup Scripts

In our form pages, we will need to add the following 2 scripts in order to input information into Analytics

Script 1: Load Jquery

<script src="//code.jquery.com/jquery-1.7.2.js"></script>

* please note that jquery MUST load before 2nd script PLUS make sure that your page does not have other jquery or conflicting loads of scripts.

Script 2: Javascript Event Tracking for Form

<script type="text/javascript">
(function($) {
$(document).ready(function() {
$(':input').blur(function () {
if($(this).val().length > 0) {
ga('send', 'event', 'contactf', 'completed', $(this).attr('name'));
}
else {
ga('send', 'event', 'contactf', 'skipped', $(this).attr('name'));
}
});
});
})(jQuery);
</script>

The above script reads your form and checks if length of each field in form is more than 0 characters. If field is empty, it sends an event tracking (using the latest universal analytics code) with the label “skipped” and the field name. If the field is not blank it will label the field in analytics event tracking as “completed”.

In addition, you will want to add the following to your form processing script

On script, if form was submitted correctly ->
<script>ga('send', 'event', 'contactf', 'completed', 'success');</script>

Else ->
<script>ga('send', 'event', 'contactf', 'completed', 'problemwithform');</script>

real-time-event-tracking

message-sent

See our Video How-To

* special thanks to Lunametrics for initial data and help with their article

Phone Call Event Tracking with Google Analytics & Twilio Number

This article explains in a simple manner how to track phone calls and call duration with twilio phone numbers and input into google analytics (universal) for event tracking.

Step 1 – Make sure you have google universal analytics on your website

If you don’t, please install the latest tracking code or upgrade at google.com/analytics

Google Analytics Universl Code

Step 2 – Register with twilio and get a phone number

Register and login to twilio.com

Twilio

Step 3 – Create script to input into google analytics

All you have to do is add the following code to a webpage on your server.
DON’T FORGET TO:
a. change ANALYTICSACCOUNTID to your account analytics account id (“UA-xxxx-xx”)


<?php

$datetime = date('m-d-Y--H:i:s');
$call=$_GET['CallDuration'];

header("Location: http://www.google-analytics.com/collect?v=1&tid=ANALYTICSACCOUNTID&cid=123&t=event&ec=Contact&ea=Call&el=$datetime&ev=$call");
exit;

?>

Step 4 – Reference script in twilio

After you login to twilio, on main dashboard page, click on “numbers” page and click on your phone number. Under “voice” section, click on “optional voice settings” in order to open more options and add url of script we just created to “Status Callback URL” and click on “save changes”.

* see google guidelines at Google Analytics Universal – Measurement Protocol Developer Guide –https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide

Status CallBack URL

Step 5 – Test in Analytics

Make a phone call and look at the real-time events section and test over time.

Look at analytics events

Hope you enjoyed this simple video. We love twilio and analytics, especially the bridge between offline and online.

Let us know if you have any questions. We’ll be happy to help!

Video Transcription:

Hey everybody. This is Ori from Astral Web. I’m very excited to create this video to show you how we bridge the gap between the offline and online world. in this video we’re going to track everytime someone calls our phone number, we’re going to put into google analytics the duration of the call. This is a very simple example so you can understand what’s going on and you can build upon that. Very cool thing – let’s dive into it very quickly. The first thing we want to do is buy a twilio number. Twilio is a really nice company and enbales you to add programmatic addons. Go to twilio.com and register and we recommend them. After you register with twilio , login and click on phone number and go under the voice section under optional voice settings and status callback url. What that means is anytime a phone call is completed, at the end of the call it will trigger the url you specify. We will create this script in a second. The script will then take information from twilio and input it into google analytics. Very cool!

Let’s look at the file. eventtracking.php. Let’s go to our server via ftp client and edit eventtracking.php. All you have here are 3 or 4 lines. What i actually did was included the date and the time in order to track in analytics when the call was made and the GET field we receive from twilio. After you get the time and the date from the server plus you might want to adjust the time if your server time is different from you home or work computer. After that you will use the latest google analytics universal url (/collect/). If you don’t have analytics universal you will need to install on website. Let’s look at code and check if we have latest analytics universal code. You can also check in analytics in admin, tracking info and tracking code. It should say, this is the universal analytics code… It came out a few months back (as of 2013). Looking at the redirect header url, google analytics enables you to pass offline information via a collect url in a very simple manner. Now you have to insert different fields. TID is the account id starting with UA dash …. CID is just a userid and this case we don’t use it. Now we specify that we want to track an event. EC category is called contact. EA is the action is called call and the label is the date time and the value is the call duration. So anytime someone calls you at the end of the call, twilio will go to your specified url and the script will give analytics the call duration. And i’ll show you how it looks. In the events section in analytics, you’ll be able to see time of calls and durations. You can translate into minutes instead of seconds. To test, make a phone call and go to google analytics, real-time and look into events and make sure it works correctly.

If you’re running a pay per click campaign, you might want to have different phone numbers
for your landing pages or from SEO. Try to have a unique twilio number for your website, different from your regular store or other numbers for better tracking. Super simple code and works real well. If you have any questions, i’ll be happy to share and answer questions.

Contact Form 7 WP – How to Add Event Tracking on New Universal Google Analytics

After searching for about 20 minutes, i could not find any hooks to explain how to track events in analytics for a wordpress site we are using (contact form 7). All you have to do is: 1. Make sure you have the latest google universal analytics code google-analytics-new-code 2. Go to Contact Tab in wordpress Admin contact-tab-form-7 3. Edit your form and scroll to bottom to “Additional Settings” additional-settings Enter the following: on_sent_ok: "ga('send', 'event', 'Contact Form', 'sent');"