7

Cross-post from Stackoverflow

Here's the problem I am having:

Currently, we need to track across www.chess.com and secure.chess.com. However, I cannot set the domain to .chess.com because the cookie causes some problems on another domain, live.chess.com.

So, to work around this, in code - I do something like this:

<? if (HTTPS) { ?>
    <script>
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXX-01']);
    _gaq.push(['_setDomainName', 'secure.chess.com']);
    _gaq.push(['_trackPageview']);
    </script>
<? } else { ?>
    <script>
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXX-02']);
    _gaq.push(['_setDomainName', 'www.chess.com']);
    _gaq.push(['_trackPageview']);
    </script>
<? } ?>

However, this forces us to maintain 2 analytics accounts (UA-XXXXX-01 and UA-XXXXX-02) and creates a separation between HTTPS and HTTP traffic.

How can I set this up so that ONE analytics account will track both secure.chess.com and www.chess.com without setting a top level cookie (.chess.com)?

1 Answer 1

1
<? if ( %%HTTP_HOST%% != 'live.chess.com' ) { ?>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-01']);
_gaq.push(['_setDomainName', '<? echo %%HTTP_HOST%% ?>']);
_gaq.push(['_trackPageview']);
</script>
<? } ?>

(Where %%HTTP_HOST%% is a variable generated by your server-side script)

Edit: To confirm, the following code is included on all pages generated at secure.chess.com and www.chess.com and no script errors display at secure.chess.com correct?

<script type="text/javascript">
  (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>
3
  • I have tried this approach, and it still only tracks www.chess.com and not ever secure.chess.com :\
    – leek
    Nov 7, 2010 at 5:06
  • @leek - Updated per comments
    – danlefree
    Nov 7, 2010 at 6:27
  • My apologies, your original answer was correct. Apparently I hadn't waited long enough for GA to update. Thanks!
    – leek
    Nov 8, 2010 at 19:13

Your Answer

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

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