Tech Tip: Integrate Google Analytics into Submission Form DataPages

 

Caspio Submission Forms can be configured to capture the user tracking information used by Google Analytics.  This way you get great information that pertains directly to “active” site users.  Google Analytics also offers a tool to create URL’s tagged with additional information so you can monitor the efficiency of individual online campaigns.

Save Google Analytic Data through Submission Forms

This solution is adapted from an article on Analytics Talk entitled Integrating Google Analytics with a CRM.  This article assumes you have already created a Submission Form.

Steps to log Google Analytics information in new record submissions:

1.  Add the following 7 fields into your table.

In the Caspio Bridge Explorer window go to the Tables view and select your Submission Form’s base table.  Click the Design button to open the table in design view.  Add the following 7 fields.  The data type should be set to Text(255).  Press Close and Save when prompted.

  • GA_Source
  • GA_Medium
  • GA_Term
  • GA_Content
  • GA_Campaign
  • GA_Segment
  • GA_nVisits

Add New Google Analytics Fields

2.  Add the fields to your Submission Form

Go to the DataPages view and select your Submission Form.  Open the DataPage wizard by clicking the Edit button.  Proceed to the Select Fields screen.  Move all of the Google Analytics fields to the right-hand panel using the arrow button.  Click Next.

Add the Fields to the Submission Form

3.  Insert header and footer sections

Click on the Insert button at the lower right-hand corner of the DataPage Elements panel.  Select Header and Footer to insert these sections.

Insert Header and Footer Sections

4.  Paste the following JavaScript into your footer

Select the Footer section and paste the following JavaScript.  Press Finish to save your DataPage.

<script type=”text/javascript”>var gaJsHost=((“https:”==document.location.protocol)?”https://ssl.”:”http://www.”);document.write(“<script src=’”+gaJsHost+”google-analytics.com/ga.js’ type=’text/javascript’>”+”</sc”+”ript>”);</script><script type=’text/javascript’>var pageTracker=_gat._getTracker(“UA-1-1″);pageTracker._trackPageview();function _uGC(l,n,s){if(!l||l==”"||!n||n==”"||!s||s==”")return”-”;var i,i2,i3,c=”-”;i=l.indexOf(n);i3=n.indexOf(“=”)+1;if(i>-1){i2=l.indexOf(s,i);if(i2<0){i2=l.length;}
c=l.substring((i+i3),i2);}
return c;}
var z=_uGC(document.cookie,’__utmz=’,';’);var source=_uGC(z,’utmcsr=’,'|’);var medium=_uGC(z,’utmcmd=’,'|’);var term=_uGC(z,’utmctr=’,'|’);var content=_uGC(z,’utmcct=’,'|’);var campaign=_uGC(z,’utmccn=’,'|’);var gclid=_uGC(z,’utmgclid=’,'|’);if(gclid!=”-”){source=’google’;medium=’cpc’;}
var csegment=_uGC(document.cookie,’__utmv=’,';’);if(csegment!=’-'){var csegmentex=/[1-9]*?.(.*)/;csegment=csegment.match(csegmentex);csegment=csegment[1];}else{csegment=’(not set)’;}
var a=_uGC(document.cookie,’__utma=’,';’);var aParts=a.split(“.”);var nVisits=aParts[5];document.getElementById(‘InsertRecordGA_Source’).value=source;document.getElementById(‘InsertRecordGA_Medium’).value=medium;document.getElementById(‘InsertRecordGA_Term‘).value=term;document.getElementById(‘InsertRecordGA_Content‘).value=content;document.getElementById(‘InsertRecordGA_Campaign‘).value=campaign;document.getElementById(‘InsertRecordGA_Segment‘).value=csegment;document.getElementById(‘InsertRecordGA_nVisits‘).value=nVisits;</script>

5.  Test the Google Analytics Fields

Double-click on the DataPage to preview it inside of Caspio Bridge.  The Google Analytics fields should be populated with some data.  The Google Analytics data within Caspio Bridge will not be accurate, but if some data appears, you know the fields are functioning.

If you have a webpage that is indexed by Google you can also test by embedding this DataPage in the indexed webpage.  Go to Google, search, and click through to that webpage.  When you arrive the DataPage should indicate Google as the GA_Source value, and also indicate the search term you used in GA_Term.

If you do not have a page indexed by Google, just embed the DataPage and then go directly to the site.  The Source should read as “(direct)”.

Test the Analytics Fields

6.  Set all of the Google Analytics Fields to hidden

Once you are sure that the form is receiving data you can edit the DataPage again.  In the Configure Fields screen, select each of the Google Analytics field and set the Form Element dropdown to Hidden.

Set All of the Google Analytics Fields to Hidden

Now whenever a user presses submit, these fields will be automatically populated with the Google Analytics data.

Create Specially Formatted Analytics Links

To better analyze your website traffic you can create specially formatted links that will provide information directly to these Google Analytics fields.  Google provides an online tool to create a special URL that you can use in your online promotions.

Google's Link Creator Tool

To fully take advantage of Google Analytics, sign up for a free account here: http://www.google.com/analytics/.  You will receive a few lines of code that must be added to your web page headers.

Note Please note: This article uses external HTML, JavaScript, or third-party solutions to add functionality outside of Caspio Bridge’s standard feature set. These solutions are provided “as is” without warranty, support or guarantee. The code within this article is provided as a sample to assist you in the customization of your web applications. You may need a basic understanding of HTML and JavaScript to implement successfully.