It’s fairly simple to integrate Google Analytics so that your campaign variables get saved behind the scenes when someone submits your wufoo form.

The code is based on the original post at analytics talk, with some small modifications for wufoo.

All we need to do is include a small javascript file that will parse our google analytics cookie and pass it to wufoo using url modification.

Here’s a 4 minute screencast of what we’ll be achieving:

Note that the code relies on the old version of the google analytics code (urchin.js update: you can find updated javascript for the new version of the tracking code at Analytics Talk, however I have not yet integrated it with wufoo) and I’m using jquery for $(document).ready functionality, but you could use your library of choice if you don’t use jQuery.

The complete javascript is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$(document).ready(function(){
    //
    // Get the __utmz cookie value. This is the cookies that
    // stores all campaign information.
    //
    var z = _uGC(document.cookie, '__utmz=', ';');
    //
    // The cookie has a number of name-value pairs.
    // Each identifies an aspect of the campaign.
    //
    // 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
    //
    // This is very basic code. It separates the campaign-tracking cookie
    // and populates a variable with each piece of campaign info.
    //
    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=', '|');
    //
    // The gclid is ONLY present when auto tagging has been enabled.
    // All other variables, except the term variable, will be '(not set)'.
    // Because the gclid is only present for Google AdWords we can
    // populate some other variables that would normally
    // be left blank.
    //
    if (gclid !="-") {
          source = 'google';
          medium = 'cpc';
    }
    // Data from the custom segmentation cookie can also be passed
    // back to wufoo via url modification
    var csegment = _uGC(document.cookie, '__utmv=', ';');
    if (csegment != '-') {
          var csegmentex = /[1-9]*?\.(.*)/;
          csegment    = csegment.match(csegmentex);
          csegment    = csegment[1];
    } else {
          csegment = '';
    }
    //modify the wufoo iframe location to pass the analytics values
    frames[0].location.href = 'https://youraccount.wufoo.com/embed/123/def/field30=' + source + '&field36=' + medium + '&field35=' + term + '&field34=' + content + '&field33=' + campaign + '&field32=' + gclid;
 
});

35 Responses to “Integrating Google Analytics and Wufoo”  

  1. 1 Samuel

    This is a great video, i wanted to know if you help me pull the same information and just output it as text on the page so that it does not have to be post in a form.

    It would be great to have your help.

    Thanks

    Samuel

  2. 2 boris

    Hi Samuel,

    The data is being stored in javascript variables so you could just document.write them onto the page if you wanted to.

    Good luck!
    - Boris

  3. 3 Rodney

    Boris,

    Will this work if you are NOT using the old Urchin.js to track your Google Analytics?

    Thanks.

  4. 4 boris

    Hi Rodney, I actually think it should work with the new tracking code too, but I haven’t tried it yet. Sorry. Basically the code might need to be modified slightly if the cookie structure has changed.

  5. 5 Rodney

    I know zero java. I’m a cut and paste hack sort of person, so I will see if I can make this work and let you know.

    Thanks for the great post.

  6. 6 boris

    Hi Rodney, one more update. It looks like the new tracking code is setup somewhat differently. Analytics Talk has updated their article with the new JavaScript which you could integrate into wufoo fairly easily (though again I haven’t done that yet).

  7. 7 Rodney

    Thanks Boris. I’m going to give it a try now. Cross your fingers!

  8. 8 Rodney

    Well I gave it a try and it does not seem to be working. I attached the java to this page on my site

    http://www.reachd.com/uberseo/register

    Here is the java file i attached to the page

    http://storage.ubertor.com/cl5218/site/javascript/569.js

    Submitted the form to see if it would work and no go :(

    I am using the old urchin code on my site so your example above should work.

    Any ideas where I might have gone wrong?

  9. 9 boris

    Hi Rodney,

    It looks like you’re using prototype on your page, so you’ll need to replace $(document).ready (which is jQuery) with http://newrelease.co.za/web-applications/jquery-documentready-and-the-prototype-equivalent/

    Good luck,
    - Boris

  10. 10 Rodney

    Boris,

    Success!! It worked – Sweet :)

  11. 11 Mike Belasco

    Hi Boris,
    Any chance you could take a look at my implementation? I’d really appreciate it as I am getting very frustrated. It doesn’t seem like the script is executing.

    Thanks!
    Mike

  12. 12 boris

    Mike, sure thing, you can see it at work at http://www.culturalcare.com/applyfree

    Good luck!
    - Boris

  13. 13 Mike Belasco

    Thanks Boris, It looks pretty similar to yours. I am sure I am missing something small, but can’t seem to find it. Here is the URL http://www.seoverflow.com/local-search-seo-audit-info.html

    THank you!

  14. 14 boris

    Hi Mike,

    When browsing to that URL with firebug script debugging enabled I get a javascript error which might be causing problems:

    _uGC is not defined
    http://www.seoverflow.com/javascript/scripts.js
    Line 5

  15. 15 Mike Belasco

    Boris,
    Is _uGC a function in jquery?

    Thanks!

  16. 16 boris

    Hi Mike,

    A couple other things I noticed;

    1. It looks like you’re including two different versions of jquery on this page, http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js and javascript/jquery.js (you should remove one of them)

    2. You’re using the newer version of the google analytics tracking code (ga.js), as I mentioned in the original post, my code is for the older code (urchin.js). You can get the older version of the code in your google analytics account.

    Good luck!
    - Boris

  17. 17 Mike Belasco

    Ok Boris,
    I am trying to configure this thing to work with the new snippet. Check out what I have now. They only problem I am having is accessing the iframe to change the URL. Got any tips?

    PS feel free to refer to this example once it is working for folks with the new snippet, and thanks so much for your help!

  18. 18 Mike Belasco

    Boris,
    I got it, Thanks so much for yoru help!!!

  19. 19 Vince

    Hi,
    Is it possible to also capture the PPC campaign name and ad group name?
    I noticed this feature was available in a competitor product.
    Thanks

  20. 20 boris

    Hi Vince, this script only captures the values in the google analytics cookie, for more info on what that provides see http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55579 or try examining the cookie with a sample campaign. You’ll see that some PPC campaign information will be captured.

  21. 21 Andrew

    Hi Boris it’s working!!
    I gave a try witth sample campaign and it gives the same PPC campaign results…
    Thanks a lot.

  22. 22 rob

    Hi Boris – thanks very much for publicizing this information.

    Now that Wufoo have added the JavaScript version of embedding the wufoo form code, how does that change the implementation of google analytics from the iframe version?

  23. 23 boris

    Hi Rob,

    It should be possible to pass parameters to the javascript embedded version using defaultValues, see http://wufoo.com/docs/url-modifications/

    Take care,
    - Boris

  24. 24 Tony

    This does not work at all with the new google analytics code. This is very frustrating as I’ve spent many hours trying to figure out another way to no avail.

  25. 25 Eugen Oprea

    Hi Boris,

    Thanks for sharing this.

    I am currently using Wufoo forms and I would like to track the submission of a form as a goal in Analytics… So, once someone submits a form, I want GA to track it as a goal.

    Will this be possible with your configuration?

    Thank you!

    Eugen

    PS: A submit to comments feature on your blog would be great.

  26. 26 boris

    Hi Eugen,

    You don’t need my technique to accomplish that; just set wufoo to redirect to a url that you control upon form submission and set that url as the google analytics goal.

    Good luck!
    - Boris

  27. 27 Thomas

    Any chance of an updated version for the newer google analytics version?

  28. 28 boris

    Hi Thomas, unfortunately I don’t have time to look at this right now, I hope you can get it to go with the new version!

  29. 29 Tim

    Heyo,

    to those that want to update for latest version of GA tracking code…

    try adding the following just after the $(document).ready(function(){

    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;
    }

    not my own solution.. the original poster of the technique updated their blog post:
    http://cutroni.com/blog/2009/03/18/updated-integrating-google-analytics-with-a-crm/

    cheers
    -Tim

  30. 30 Wedding Stationery

    I want to be able to track the users keywords when the complete our online form when searching for our wedding stationery. I have had a look at the code at http://cutroni.com/blog/2007/10/29/integrating-google-analytics-with-a-crm/

    I cant appear to get this working on frompage if anyone has any tips much appreciated.

  31. 31 boris

    Hi there,

    I’m not seeing a form on your homepage? Also, what is the exact problem you’re having?

    Take care,
    - Boris

  32. 32 Marcus Layton

    Hi Boris,

    Can I pay you to do this for me by any chance? I am not able to figure it out mate :( . My Website is http://www.bizzbuzz.com.au (includes my email in the contact us section)

    Would love to hear from you.

    Cheers!

  33. 33 boris

    Hi Marcus,

    I’m afraid I’m not doing freelance work at the moment, but I’m sure you can find some web guys to help you out for a little bit. Best of luck!

    - Boris

  34. 34 Wax

    Hi,

    Can anyone confirm that Tim’s solution to the new GA tracking code works? I’ve tried it without success. But it may just be me.

    Or if there’s another approach I’m all ears.

    Thanks so much.

  1. 1 Autofilling Wufoo Form Fields & Other Tricks http… « Web Development Journal


Leave a Reply