1

Currently our main website is served without SSL at http://example.com. Our shop is served on a subdomain via at https://store.example.com.

Our main site uses the traditional Google Analytics code:

var _gaq = _gaq || [];
 _gaq.push(
    ['_setAccount', 'UA-XXXXXX-X'],
    ['_setDomainName', 'www.example.com'],
    ['_trackPageview'],
    ['hq._setAccount', 'UA-XXXXXX-X'],
    ['hq._setDomainName', 'www.example.com'],
    ['hq._trackPageview']
);
(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);

Our shop at uses the new Universal Analytics:

    ga('create', 'UA-XXXXXX-X', 'auto', { 'allowLinker': true });
    // Load the plugin.
    ga('require', 'linker');
    // Define which domains to autoLink.
    ga('linker:autoLink', ['store.example.com']);
    ga('send', 'pageview');
  1. Should both the main site URL and the store subdomain's URL be included in the ga('linker:autolink', []); line?
  2. Does the linker section need to be added to the main websites URL code?

Currently all metrics for both sites are showing up under our main websites Google Analytics account, including visits, pageviews, etc. to our shop's URL, which is fine and how we want it to be.

  1. Would like to create a new/separate view where we only see traffic to the store's subdomain. I've created the new view in the account, but I'm not getting any data back at all. How do I need to set up the view to in the settings (such as "Website's URL": We added https://store.example.com here) or do we need to work with filters?
5
  • For number 3, the second part of my answer here might help. As for 1 and 2, since it seems everything is working as you want, and it's unclear what you're trying to track (that's not already working), I'd suggest having a look the section here on Cross Domain Auto Linking. The example there defines both domains to autolink.
    – dan
    Jan 27, 2015 at 5:32
  • Thank you @dan , I guess what's confusing me is that the autolinker code is placed on the subdomain, and not the main domain. But like you say, if the data is coming in fine, I guess it doesn't matter. Now I just need to get the new view to work correctly. I'll visit your link now. Thank you!
    – Anthony GP
    Jan 27, 2015 at 17:12
  • @dan this comment here: "Alternatively, you can add another profile to Google Analytics for the subdomain, and create a filter to show only traffic for the subdomain:" are you talking about setting up a whole new profile with different tracking code for the subdomain?
    – Anthony GP
    Jan 27, 2015 at 17:21
  • Take a look at the link in that answer which explains this.
    – dan
    Jan 28, 2015 at 0:40
  • @dan Ok, so I used the method to create the filter you mention in this post: webmasters.stackexchange.com/questions/52424/… on the new store subdomain view that I created. I'm just now realizing that, that filter should be placed on the main site account, and not the sub, is that right? For example when I click on my store sub view and look at the data, it's still showing data from the main part of the site.
    – Anthony GP
    Jan 29, 2015 at 15:22

2 Answers 2

2

I'd recommend you run Universal Analytics on both your main site and subdomain under a single property and then create views to separate the sites, as well as a view of everything combined. The downside of this is you'll lose an historical data. This will allow you track the full funnel + revenue by source and a bunch of other metrics you'll want to collect down the road.

Once both your domain and subdomain are running w/ the same tracking code/property, you'll need to add the autolinker like:

ga('linker:autoLink', ['domain.com', 'subdomain.domain.com']);

Finally you'll have to create separate views if you want to separate subdomain vs. main domain. To do this select "Admin" click the view dropdown and select "Create New View". Go ahead and name the view and select "Create View".

You'll need to create two filters, the first is a prepend URL by hostname. By default GA, only shows what's after your domain (ex. /subdirectory). When dealing with subdomains, you'll want to see the full URL. Here's a tutorial: https://support.google.com/analytics/answer/1012243?hl=en

The next filter tells GA to only include the subdomain. Select "Filter" then "New Filter". On this screen, select the "Select Filter Type" dropdown, select include only. On the "Select source or destination" dropdown, select "traffic to hostname" and then finally enter your subdomain here.

5
  • Thank you very much! I upvoted. Unfortunately, management will not allow me to go full Universal because of the years of data we'd lose.
    – Anthony GP
    Jan 29, 2015 at 15:15
  • Why don't you add classic GA to the subdomain then? I'd recommend you keep the version you run consistent.
    – Alex L
    Jan 29, 2015 at 15:37
  • Good point, and one I've brought up with them before. The subdomain is an ecommerce store and it looks like we'll get more out of universal when it comes to how many things we can track with it. Ugh!
    – Anthony GP
    Jan 29, 2015 at 21:44
  • They want to use classic GA on the marketing site and Universal Analytics on the subdomain?
    – Alex L
    Jan 29, 2015 at 23:23
  • Yes, the marketing site is years old, with a lot of data, so switching from traditional GA isn't an option. The store sub is new and they were able to use Universal. Now I'm just fighting to correctly setup a view for the sub.
    – Anthony GP
    Jan 29, 2015 at 23:29
0

In order to get my view to work correctly, I had to go back to my filter for the new view and add in the "https://" into the hostname. Previously, I only had "store.example.com". Thanks to all who added their very helpful advice!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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