Search code examples
javascriptgoogle-analyticsanalyticstracking

Why won't Google Analytics track page views from my off-site order form?


I must be doing something wrong here. I'm trying to use Google Analytics to track hits on a form hosted by InfusionSoft (our CRM/etc provider) on their domain. We want to track hits under a separate domain in GA.

here is the form in question: our order form

I have tried several forms for the GA code -- first the async snippet, then the 'traditional' snippet, now back to the async. Here is the async code I'm trying to use (inside the <body> tags):

Near the top of the page

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_setDomainName', 'oursite.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview', '/saleform/67']);
</script>

Further down the page

<script src='https://ssl.google-analytics.com/ga.js' type='text/javascript'></script>

Relevant information

  • Using Firebug or Chrome's dev tools, I don't see any errors coming from GA when using this code.
  • Tracking is already working on oursite.com, but does not receive data from this page.
  • In Firebug's console, _gaq and _gat seem to be working fine (no errors, they appear as objects with a lot inside)
  • __utm.gif is NOT being requested. I know this is a Bad Thing but am unsure what to do about it.
  • Using a Firefox extension to view cookies, I do NOT see any cookies being set for the domain specified in the above code (or the site hosting the form). edit: after including _setAllowLinker on our site, cookies DO seem to be working (showing up on the page)

Additionally, I have tried manually firing the _gaq.push(['_trackPageview', '/saleform/67']); method from the JS console (with no luck--the page does not show up in GA).

Please let me know if there's any pertinent information missing from this post and I'll be happy to update it. Thanks in advance for any insight you can offer.


Solution

  • After much fiddling with the code on the various pages, I've found a solution that works to my satisfaction. I'll detail the three things that seemed to make the difference in this case.

    Hope this helps someone out there, and don't forget to vote up if it helped you!

    1. Set up the normal GA code on our own website, including _gaq.push(['_setAllowLinker', true]);

    2. On the order forms (hosted by InfusionSoft in our case) set up the GA code as instructed by their website, but include _gaq.push(['_setDomainName','none']);

    3. Important: add onClick handlers in javascript which call _gaq.push(['_link', 'http://your.link.tld/etc']);

    For point 3, I used a snippet of jQuery to identify links to order forms on the webpage and bind the GA function call with click() -- code for that is below.

    <script>
    jQuery(document).ready(function() {
      jQuery("a[href*='/sale-form'], 
        a[href*='/another-order-form-link'],
        a[href*='your_site.infusionsoft.com/saleform/']").click(function() {
          _gaq.push(['_link', this.href]);
          return false;
        });
    });
    </script>
    

    Explanation of code:

    • wait for the page to be ready
    • search for any links with href containing your search terms (more on that here
    • bind the _gaq.push(['_link', this.href]); function call to the onClick event handler for any links that were found in the previous step

    Additional note: if you include this jQuery code, you'll have to have the jQuery library loaded. Also, obviously remove the <script></script> tags if you're including this in a .js file.