I'm trying to serve static content from a cookieless subdomain s.mydomain.org.uk, so that image/css requests from pages at www.mydomain.org.uk don't get sent with needless cookie data. The trouble is that Google Analytics insists on adding its cookies (_utma, _utmz) to those requests anyway! My code is:

<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>
  <script type="text/javascript">
    try {
      var pageTracker = _gat._getTracker("xxxx");
      pageTracker._setDomainName("www.mydomain.org.uk");
      pageTracker._trackPageview();
    } catch (err) { }
  </script>

Any ideas?

<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>
  <script type="text/javascript">
    try {
      var pageTracker = _gat._getTracker("xxxx");
      pageTracker._setDomainName("www.mydomain.org.uk");
      pageTracker._trackPageview();
    } catch (err) { }
  </script>

Any ideas?

This alone won't do the trick... you'll have to do some additional tweaking in your httpd.conf's virtual hosts section for the particular subdomain in order to disable cookies...

Supposing I plan on delivering all my JavaScript from js.example.org, this is what I need to add to my Vhosts section for the subdomain...

<Location />
    <IfModule mod_php5.c>
        php_admin_value session.use_cookies 0
    </IfModule>
    <IfModule mod_php4.c>
        php_admin_value session.use_cookies 0
    </IfModule>
</Location>

These two blocks will effectively prevent the subdomain from sending any cookies for both PHP4 and PHP5.

Note: If you don't use the IfModule blocks, apache will fail trying to load httpd.conf - as this syntax validates only after the php module has been loaded.

In effect a typical vhost block (above code included) will look like..

<VirtualHost x.x.x.x:80>
    ServerName js.example.org
    ServerAlias [url]www.js.example.org[/url]
    DocumentRoot /home/example/public_html/js
    ServerAdmin [email]webmaster@example.org[/email]
<Location />
    <IfModule mod_php5.c>
        php_admin_value session.use_cookies 0
    </IfModule>
    <IfModule mod_php4.c>
        php_admin_value session.use_cookies 0
    </IfModule>
</Location>
</VirtualHost>

Once the code has been added, you need to restart apache using the command:

apache2ctl restart

If all goes well, you'll have the desired effect when you reload your site. If you still see those ubiquitous utm cookies being delivered, just clear up your cache and cookies before reloading your site again... and voila!!

On a sidenote, if you don't have access to your httpd.conf, I believe the same can be achieved by placing a .htaccess file in your subdomain root with appropriate syntax. You'll have to Google a bit for that :)

Cheers,
m^e

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.