Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm trying to set up tracking on a project that I'm working on.

  1. The main site is at http://www.example.com/
  2. The order page is at https://www.example.com/index.php

Currently they have two different profiles under separate domains:

  1. Main Site: UA-aaaaaaaa-1
  2. Order Site UA-aaaaaaaa-2

This isn't giving me the results I want. When on the order page, I would like to see where on the main page users came from. Also, when on the main page I'd like to see when they navigate away to the order page, right now I can't tell the difference between an exit and order page click.

I'm not even getting the main site as a referrer to the order page.

What am I doing wrong? Should they be under one profile? Or two like I have them. Should I be setting the domain name (_setDomainName)? Should I be using _link() when linking to the order page. I can't find the right resource for what I need.

share|improve this question

migrated from stackoverflow.com Apr 14 '11 at 18:08

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 8 down vote accepted

You need to set up cross-domain tracking in Google Analytics.

Follow the linked instructions to do the following:

  • Set up a master profile for your primary domain without filters.
  • Create a profile especially for cross-domain tracking and re-use your tracking code.
  • Modify your cross-domain profile with a filter to show the full domain in your content reports.

In reference to the comment - "my main issue comes from http -> index.php and https -> index.php being recognized as the same page":

Here are some things you can try to differentiate between http://www.example.com/index.php and https://www.example.com/index.php (two separate pages):

  • Rename the https index.php to something else (e.g. index-cart.php). This is probably the best/easiest thing to do.

  • Rename the http index.php to something else and set as the default document (e.g. default.php). This might be quite easy as your are probably referencing the site root just with href="/"

  • Alias the https www subdomain to something else (e.g. https://checkout.example.com). This is just a DNS change, and hopefully a simple change to your config file to point to the new secure alias. This will allow you to do cross-domain tracking exactly as per the Google documentation.

  • Add a parameter to your links to the secure pages (e.g. href="https://www.example.com/index.php?foo=bar". This would allow you to differentiate between the two index pages in GA. This is not the best option but should be easy to implement without breaking any business logic.

Hope this helps. Please report back on any methods which work for you.


Cross-Domain Tracking in Google Analytics: * http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html

share|improve this answer
    
@Ciarian - I think you were trying to comment that you answer meant was in reference to "my main issue comes from http -> index.php and https -> index.php being recognized as the same page." If you have a comment on the question please post it as a comment or edit your answer to clarify it. –  RandomBen Apr 15 '11 at 11:04
    
I chose this as the answer because it was the most informative and it did mention what I had to end up doing. I just renamed the https://...index.php file to order.php and put it under the same profile. Turns out it didn't cause the complications I was worried about. –  Vian Esterhuizen Apr 15 '11 at 15:04

Virtual page views can be used to aggregate data from multiple subdomains and protocols under a single profile - definitely the easiest way to look at all analytics data gathered for a domain in a single place.

Here's a simple PHP example for tracking virtual page views across subdomains (will appear in reports as /subdomain/uri) or protocol (will appear in reports as /secure/uri):

<?php
    $domain = '.example.com';
    $uri = $_SERVER['REQUEST_URI'];
    /*
     * create a virtual page view URI for subdomains other than "www"
    */
    if ( $_SERVER['HTTP_HOST'] != 'www'.$domain ) {
        $uri = '/' . strtok( $_SERVER['HTTP_HOST'], '.' ) . $uri;
    }
    /*
     * create a virtual page view URI for HTTPS requests
    */
    if ( @isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ) {
        $uri = '/secure' . $uri;
    }
?>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_setDomainName', '<?php echo $domain; ?>']);
  _gaq.push(['_setAllowHash', false]);
  _gaq.push(['_trackPageview', '<?php echo $uri; ?>']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

You'll want to change the script to accommodate your configuration if you serve content under "www.domain.com" named "secure" or with the same name as subdomains.

share|improve this answer

I think you can put both under the same profile. I do the same for http/https combinations. To really track internal navigation you can call the trackPageview part via Javascript as an onClick event on the specific links. There are some resources in the web to handle this (e.g. here)

share|improve this answer
    
Thanks for the link, it was helpful but it's not quite what I'm looking for. I agree with you that they should probably be under one profile, my main issue comes from http -> index.php and https -> index.php being recognized as the same page. –  Vian Esterhuizen Apr 12 '11 at 21:08
    
Ah,OK. Maybe a renaming of the https-index.php into e.g. https-order.php would be the easiest way? –  Daniel Apr 12 '11 at 21:16
    
I was thinking about that but for this project that's probably too late. Moving forward I'm going to see if our ecomm template would work with that. –  Vian Esterhuizen Apr 12 '11 at 21:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.