Customer Forum

Integrating Workbooks CRM with Google Analytics for Web2lead

Sam (Workbooks Online) Posted: 2016-09-22 10:31

It is possible to integrate Google Analytics with the Web2lead functionality in Workbooks CRM, enabling you to capture information about how visitors arrived at your website.

Google Analytics provides free tracking code which is placed on every page of your website.  This code is used to send visitor data back to the Google Analytics engine and drives the reports you find inside the Google Analytics  portal.

Part of that code creates a specific cookie in the visitors’ browser which stores information about how the visitor found your site.  This information is really useful if you are trying to measure the success of your online marketing activities.

By tracking how visitors arrived at your site, you can link this information back to a marketing campaign in Workbooks CRM and begin to measure your return on investment.  So you can see if the money you are spending on Google Adwords is really delivering value back to the business.

The specific cookie which stores how a visitor found your site is called the ‘_utmz cookie’ and normally stores the following attributes:

Name Internal value Description
SOURCE utmcsr This is the source site from which the visitor arrived.  Examples values would be ‘google’, ‘bing’ or the address of a referring site.
MEDIUM utmcmd This is the method by which the visitor found your website.  Example values would be

‘cpc’ which stands for cost per click and indicates Adwords

'organic’ which indicates  search engine results

‘referral’ which indicates the visitor arrived from a referring site.

TERM uutmctr This is the search term entered by the visitor if they arrived via a search engine.  E.g. ‘Web based CRM’
CAMPAIGN utmccn This is typically set to the Adwords campaign name, to indicate which advertising campaign delivered the visitor.
CONTENT utmcct This is typically set to the content of the advert and is used for A/B split testing.
GCLID utmgclid This is only set if Google Adwords has auto tagging enabled.

By capturing this information when a visitor completed a web2lead form, we can see which visitors are turning into leads and ultimately which leads convert into sales.  It also means you can run reports in Workbooks CRM which identify which Keywords are working most effectively for you.

If you are based inside the European Union you should also consider the impact of the recent EU directive on Cookie Law.  Here is a link you mind find useful on the subject.

We don’t offer legal advice at Workbooks, but our take on this directive is as follows:

  • You don’t need to ask permission to use cookies which are required to deliver the service.
  • You do need to ask permission if you intend to use cookies to read/access information stored on their equipment.

So our advice would be, on your privacy policy, be clear you are using cookies and on your web2lead forms, specifically mention that using this form indicates that the visitor is agreeing to your privacy policy and the use of cookies.

Example Scenario

In this scenario you want to create a ‘Contact Us’ form on your website and you want to capture how visitors found your website originally.  In addition you want associate leads automatically with 4 different campaigns:




Google Advertising

Adverts you promote on Google Adwords

Bing Advertising

Adverts you promote on Bing


Leads that arrive via organic search engine results

GetApp Advertising

Leads that arrive from the website, via referral.


Step One – Create Campaigns

Create Your Four Marketing Campaigns in Workbooks and mark them as Active.

Start > Marketing > Campaigns > New Campaign.

Once you have created the campaigns you will need to note down the ID of each campaign.  You can get this by viewing the campaign landing page and adding the campaign ID from the list of available columns to be displayed.


Step Two – Ensure you have Google Analytics setup on your website

You will need to register for a Google Analytics account and setup your website accordingly, if you haven’t already done so, you can find details here:

Step Three – Setup additional Workbooks Cookie on your website.

Every time a visitor visits your website Google Analytics creates the _utmz cookie.  It is common for visitors to visit your website several times before they complete any type of form, therefore using the values in the _utmz cookie will only give us details of how they arrived just before completing a form.

Therefore to get an accurate picture of how your visitor initially found your website we would recommend copying the values from the google _utmz cookie into an _workbooks cookie.  You can then record how they first arrived at your site and also how they arrived just before they completed a form.

Example Code:

To create a _workbooks cookie from the _utmz cookie you should place the following example code on every page of your website below the google analytics tracking code. (Note: You will need to have jQuery enabled on your website for this code to work).

//Creating Workbooks Cookie from UTMZ Cookie.
   var utmz=$.cookie('__utmz');
     $.cookie('__workbooks',utmz,{path:'/',expires:'Mon, 25 May 2040 09:00:10 GMT'});

Step Four – Create additional fields in Workbooks to store the cookie information

We now want to create additional custom fields to store the cookie information.  In the custom field configuration area add the following six fields to the lead record:

Field Name Description
Web Workbooks Cookie This will hold the complete _workbooks cookie. i.e. how the visit first arrived at the website
Web utmz Cookie This will hold the complete _utmz cookie i.e. how the visit arrived at the website just before completing the form.
Web Source This is the source site from which the visitor first arrived (extracted from the _workbooks cookie).  Examples values would be ‘google’, ‘bing’ or the address of a referring site.
Web Medium This is the method by which the visitor found your website.  Example values would be: cpc, organic or referral
Website Term This is the search term entered by the visitor if they arrived via a search engine.  E.g. ‘Web based CRM’
Website Campaign This is typically set to the Adwords campaign name, to indicate which advertising campaign delivered the visitor.
This is typically set to the content of the advert and is used for A/B split testing.


Step 5 – Create the Web2lead key and form.

In the configuration area of Workbooks you will need to create a web2lead form and key.

When you download the complete form you get every possible field listed. The first thing you do is to remove the fields you don’t need.

Hidden/Displayed Fields

It is worth noting that the example below uses both displayed and hidden fields. Displayed fields are used to capture information directly from the visitor, such as their name and email address.

Hidden fields are used to capture information silently and pass the value into Workbooks, these will be used to capture the Google Cookie information and also values like lead source. See comments below between <!-- --!> tags for further explanation.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
< html xmlns="">
   <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
   <title>New Sales Lead</title>
   <script src=""></script>
   <script src=""></script>
   <div id="page">
     <h1>New Sales Lead</h1>
     <form id='wb_form' method='POST' action=''>

<!-- The web_key value below, should be the unique key for your web to lead form. -->

       <input type ='hidden' name='web_key' value='c25ea1ffc904f4ca63da5ea9e5caa8f7b3226d8e' />

<!-- The server issues a Redirect to the URL below when the form submission succeeds. You would typically show a ‘thankyou’ screen. -->

       <input type ='hidden' name='success_url' value='/success.html' />

<!-- The server issues a Redirect to the URL below when the form submission fails. You would typically invite them to change the input; best practice is to implement client-side validation which would prevent this being an issue. -->

       <input type ='hidden' name='failure_url' value='/failure.html' />

<!-- Below is the lead name and will be displayed on the form. -->
       <label for="person_lead_party[name]">Name [Required]</label><input name="person_lead_party[name]" class='required' /><br />

<!-- Below is the person’s role and will be a pick list displayed on the form. When using pick lists in web2lead it is important to note that if the field in workbooks is configured as a ‘restricted’ pick list, then the values on the form must match the values in the pick list in Workbooks -->

       <label for="person_lead_party[person_job_role]">Job Role</label><select name='person_lead_party[person_job_role]' >
       <option value='Admin Assistant/PA' >Admin Assistant/PA</option>
       <option value='CEO/Managing Director/Business Owner' >CEO/Managing Director/Business Owner</option>
       <option value='Sales Team Member' >Sales Team Member</option>
       <option value='Software Developer' >Software Developer</option>
       </select><br />
<!-- Below is the organisation name and address fields, these will be displayed on the form. -->
  <label for="org_lead_party[main_location][street_address]">Street Address</label><input name="org_lead_party[main_location][street_address]"  /><br />
       <label for="org_lead_party[main_location][town]">Town or City</label><input name="org_lead_party[main_location][town]"  /><br />
       <label for="org_lead_party[main_location][county_province_state]">County/State</label><input name="org_lead_party[main_location][county_province_state]"  /><br />
       <label for="org_lead_party[main_location][postcode]">Postcode/Zipcode</label><input name="org_lead_party[main_location][postcode]"  /><br />

<!-- The fields below are all hidden.  The marketing_campaign_id value is used set the campaign value on the lead e.g. which campaign generated the lead.  The other fields are used to capture the google analytics information described above.  The exact names of these fields will be different on your form, because custom field names are always unique. The values we capture in these fields are going to be determined using the logic described in step 6. -->

       <input name="marketing_campaign_id" type='hidden' value=''/>
       <input name="cf_web_utmz_cookie_196" type='hidden'/>
       <input name="cf_web_workbooks_164" type='hidden'/>
       <input name="cf_web_source_179"  type='hidden' />
       <input name="cf_web_medium_180"  type='hidden' />
       <input name="cf_web_term_181"  type='hidden' />
   <input name="cf_web_content_182"  type='hidden' />
   <input name="cf_web_campaign_162" type='hidden' />
       <br />
       <input type='submit' />

<!-- Insert Javascript from step 6 here (see below) -->



Step 6 – Add Logic to automatically link leads to Campaigns


Now all you need to do is to populate the hidden fields when the form is submitted. You’ll probably also want to do some client-side validation before this happens. So you will add some JavaScript like this:

<script type="text/javascript">

 //The _workbooks and _utmz cookie are a single string containing the fields we need seperated by a |.  Therefore we need a function which can parse the string to separate the specific values.
 // The cookie has a number of name-value pairs.
 // utmcsr  = campaign source
 // utmcmd  = campaign medium
 // utmctr  = campaign term (keyword)
 // utmcct  = campaign content (used for A/B testing)
 // utmccn  = campaign name
 // utmgclid = unique identifier used when AdWords auto tagging is enabled

  function _uGC(l,n,s) {
 if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
 var i,i2,i3,c="-";
 if (i > -1) {
i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
 return c;

 //Here we sent the source, medium, term, content & campaign variables from the _workbooks cookie, using the uGC function above.

 var z = _uGC(document.cookie, '__utmz=', ';');
 var w = _uGC(unescape(document.cookie), '__workbooks=', ';');

 var source  = _uGC(w, 'utmcsr=', '|');
 var medium  = _uGC(w, 'utmcmd=', '|');
 var term    = _uGC(w, 'utmctr=', '|');
 var content = _uGC(w, 'utmcct=', '|');
 var campaign = _uGC(w, 'utmccn=', '|');
 var gclid   = _uGC(w, 'utmgclid=', '|');

 //The code below, is checking to see if the gclid is set.  If it is set, we know the source is from google adwords.

if (gclid !="-") {
 source = 'google';
 medium = 'cpc';

 //The code below, is initialising the wcampaign variable and then setting the value to ID of the appropriate Workbooks campaign.  

 //In this first example is the medium is ‘cpc’ which indicates adwords and the source google, we know its a google adwords campaign.  Therefore we set the campaign id to be 103, you should use the ID of the campaign you want to associate google adwords.

var wcampaign='';


 //This code below assigns bing adwords to campaign id 134.


 //The code below assigns all leads identified as coming from a search engine to campaign id 115, e.g. your SEO campaign.


 //The code below assigns all leads identified as coming from the getapps website to campaign id 117, e.g. your getapp campaign.


 //This section populates the values into the hidden fields for posting.

function populateHiddenFields(f) {
 f.cf_web_utmz_cookie_196.value  = z;
 f.cf_web_source_179.value  = source;
 f.cf_web_medium_180.value  = medium;
 f.cf_web_term_181.value    = term;
 f.cf_web_content_182.value = content;
 f.cf_web_campaign_162.value   = campaign;
 f.marketing_campaign_id.value = wcampaign;
 return true;

 $("#wb_form").validate({errorElement: "div"});
$("#submitb").click(function() {
 if (!$("#wb_form").validate({errorElement: "div"}).form()) {
return false;