It is not clear from README.txt file how to setup the module for two separate Drupal installations like http://mysite.com and https://sub.mysite.com I have activated the module on the main site, specified "Web Property ID" from Google and checked "One domain with multiple subdomains" option.

What about second subdomain site? Do I need to activate the module there too? DO I need to write the same "Web Property ID"? What about setting "What are you tracking?:" under Domains section? If I check "One domain with multiple subdomains" option, then it seems it will try to track the subdomains of my subdomain.

Reading http://www.google.com/support/analytics/bin/answer.py?answer=174090 also does not help, since we need to setup Google Analytics module for Drupal.

Comments

hass’s picture

Status: Active » Fixed

With independent databases, also configure the subdomain site like your main site. Both need to show the ".domain setting in footer

yngens’s picture

Thanks, but which one of two settings I should select for subdomain?

What are you tracking?:
A single domain (default)
Domain: sub.mysite.com
One domain with multiple subdomains

hass’s picture

Depends on how you'd like to track. All sub and main domains in one singe account - use the second selection. Google Docs are very clear... And there is nothing special in drupal

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

burningdog’s picture

Version: 6.x-3.x-dev » 7.x-1.2
Status: Closed (fixed) » Active

My issue is the same as this post, and #3 didn't clear it up for me.

I have an existing drupal site, www.example.com, which is being successfully tracked by GA. I've just created a new drupal site, a subdomain - blog.example.com - which needs to be tracked.

According to http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#... the following code needs to be present on both sites:

_gaq.push(['_setDomainName', '.example.com']);

On the subdomain site, I've configured the GA module to "One domain with multiple subdomains", which is currently the only way to get _gaq.push(["_setDomainName", into the javascript.

Taking a look at the module code (line 233):

<?php
    if ($domain_mode == 1 && count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
      $script .= '_gaq.push(["_setDomainName", ' . drupal_json_encode($cookie_domain) . ']);';
    }
?>

Unfortunately, _setDomainName gets set to $cookie_domain, the value of which on the subdomain is .blog.example.com

However, I expect it to be .example.com as I shouldn't need to change my $cookie_domain to be example.com in settings.php for the subdomain drupal site.

I would suggest the following: keep the current behaviour as the default, but if a user has entered in a value to the "List of top-level domains" textarea then use the first one as the value for _setDomainName

Is that a decent solution? Even better, add a textarea/texbot below the "One domain with multiple subdomains" radio where a user can enter their top level domain.

hass’s picture

Status: Active » Fixed

First of all open your settings.php on both sites and setup your $cookie_domain correctly:

/**
 * Drupal automatically generates a unique session cookie name for each site
 * based on on its full domain name. If you have multiple domains pointing at
 * the same Drupal site, you can either redirect them all to a single domain
 * (see comment in .htaccess), or uncomment the line below and specify their
 * shared base domain. Doing so assures that users remain logged in as they
 * cross between your various domains.
 */
$cookie_domain = 'example.com';

This should fix the issue for both sites.

If you think you need to run both sites in-depended with unique cookies/sessions, set up GA with A single domain (default) and add the _setDomainName line manually in Custom JavaScript code > Code snippet (before).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

burningdog’s picture

Thanks hass - #6 did the trick. I set $cookie_domain = "example.com" in the sub-domain site (I didn't change that value on the main site). Then I set the GA tracking option to "One domain with multiple subdomains" at admin/config/system/googleanalytics

satvision83’s picture

I have a question:
If the main website is www.website.com and subdomain is www.sub.website.com, in settings.php on www.sub.website.com the line #$cookie_domain = 'example.com'; i have to set to $cookie_domain = 'website.com'; ? Is that right?

This is my issue: http://drupal.org/node/1832048

user654’s picture

.

rohr’s picture

Note for beginners - you may need to allow for "write" capability in the file permissions of settings.php before attempting to edit this file.

rohr’s picture

Issue summary: View changes

Please note that subdomain support is already built into the newer Google "Universal" Analytics and does not require different code. Great article here on Google Analytics filters to track subdomain traffic and make sure that this is working as expected: http://www.wearefine.com/mingle/subdomain-tracking-with-universal-analyt... Also, data may take up to 48 hours to start showing in the Google Analytics dashboard.