Dot or Not

/

We often hear variations on the question “Do we need the leading dot when using _setDomainName”.

With the dot:
pageTracker._trackPageview(‘.www.lunametrics.com’);

Without the dot:
pageTracker._trackPageview(‘www.lunametrics.com’);

The _setDomainName method is used to tell GA what to set the “domain” to, for the cookies that it uses to keep track of visitor information.  This “domain” field for the cookies are used as part of the security in browsers to determine what websites can access what cookies. (You don’t want porn.com getting access to your amazon.com cookies, for example.)

The Google Analytics documentation recommends using a preceding dot.  For example: pageTracker._setDomainName(‘.www.lunametrics.com’)

The example above allows any www.lunametrics.com subdomain to access the same cookies.  (blog.www.lunametrics.com and help.www.lunametrics.com are both still “www.lunametrics.com” so the browser says this is okay)

In most cases, it doesn’t really matter whether you use ‘.www.lunametrics.com’ or ‘www.lunametrics.com’.  As long as you’re consistent across the entire website that you’re tracking. That’s part of the confusion.  Both ways work fine.

However, Google explains, in cases with multiple levels of subdomains, you can sometimes run into problems if you don’t use the preceding dot with _setDomainName.  If we had robbin.posts.blog.www.lunametrics.com the browser may not let the GA code on that page have access to cookies written with _setDomainName(‘www.lunametrics.com’), but it would allow access to cookies written with _setDomainName(‘.www.lunametrics.com’).

John is a former LunaMetrician and contributor to our blog.

  • Hi Robbin,
    this is a really good post !
    Indeed this is a reccurent question, and you make it clear !
    Really love the title of the post too 😉
    Br,
    Maars

  • PS /
    I will repost in my french blog,
    hope it will be ok for you,
    if not let me know.
    Br,
    M

  • Really good article. Always been wondering where to use the leading dot, when tracking cross several sub domains.

    This helped – Thanks 🙂

Contact Us.

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203

THE STUDIO [map]

4115 N. Ravenswood
Suite 101
Chicago, IL 60613

THE LODGE [map]

2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187