example-petstore.com

Example domain · Not a live service · Browser visits show this page · API requests get 410 Gone

Guide · Google Analytics

From Classic Analytics to Google Analytics 4

Code copied from Google’s Classic Analytics examples still contains example-petstore.com and example-commerce-host.com. It no longer measures anything, and its example links send visitors to the wrong site. This guide replaces it with Google Analytics 4.

Recognise the old code

From 2009 to 2024, Google’s guide to tracking multiple domains with Classic Analytics (ga.js) used a pet store at example-petstore.com with a cart at example-commerce-host.com. Typical lines that were copied:

_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'example-petstore.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCookiePath', '/myStore/']);

<a href="http://dogs.example-petstore.com/intro.html"
   onclick="_gaq.push(['_link', 'http://dogs.example-petstore.com/intro.html']); return false;">See my pet store</a>
<form onSubmit="pageTracker._linkByPost('www.example-commerce-host.com/petStoreCart/begin.php');">

Older variants use pageTracker._setDomainName(".example-petstore.com") with a leading dot, or _setDomainName("none"). Universal Analytics (analytics.js) code uses ga('create', …, {'allowLinker': true}) and ga('linker:autoLink', […]) instead.

What it does now

  • No data is collected. Standard Universal Analytics properties stopped processing data on 1 July 2023 (360 properties on 1 July 2024). Classic Analytics came before it. Pages with only this code are not measured at all.
  • Example links send visitors away. Links and forms with a full example address, such as http://dogs.example-petstore.com/intro.html, take real visitors to the example domain instead of your own pages.
  • Links without a scheme break. href="www.example-petstore.com" is read as a path on your own site and leads to a “not found” page.
  • Cookie settings fail silently. A browser refuses cookies for a domain the page is not on, so _setDomainName with an example domain never worked on a real site.

Remove the old code

  1. Search your templates, theme and tag manager for _gaq, pageTracker, urchin, ga.js, analytics.js, ga('create', example-petstore and example-commerce-host.
  2. Delete the whole tracking block, not only the example domain.
  3. Remove onclick and onsubmit handlers that call _link, _linkByPost or pageTracker.
  4. In Google Tag Manager, check Tags and Variables for old Custom HTML tags with Classic or Universal Analytics code, delete them, test with Preview and Submit a new version.
  5. Point example links and forms (“See my pet store”, “Continue Shopping”, /petStoreCart/begin.php) at your own pages or your real checkout, or remove them.

Install Google Analytics 4

Create a Google Analytics 4 property with a web data stream, then add the Google tag to every page, directly or through Google Tag Manager. Replace G-XXXXXXXXXX with the measurement ID of your stream.

<!-- Google tag (gtag.js) for Google Analytics 4 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>

Cross-domain measurement

Only needed when one visit spans several of your domains, for example a shop and a checkout provider. In Google Analytics 4 it is set in the admin, not in code:

  1. Open Admin › Data collection and modification › Data streams and select your web stream.
  2. Open Configure tag settings › Configure your domains.
  3. Add a condition for each of your own domains. Never add example-petstore.com or example-commerce-host.com.
  4. Save. The Google tag now adds a _gl parameter to links between these domains.

In Google Tag Manager, the same list is under Google tags › your tag › Show all. If you prefer code, set the linker domains in the Google tag:

// Only if you configure cross-domain measurement in code instead of in the admin;
// place this before gtag('config', …)
gtag('set', 'linker', {
  'domains': ['www.example.com', 'checkout.example.net']
});

Unwanted referrals

A payment provider or other external step can show up as the source of a sale. Add such domains under Configure tag settings › Show all › List unwanted referrals (up to 50 per stream). Analytics then ignores these domains as referrers (it adds ignore_referrer=true), so the visit keeps its original source, such as the ad or search that brought the customer.

Verify

  • The page source no longer contains ga.js, analytics.js or the example domains.
  • Reports › Realtime shows your own visit.
  • A link from one of your domains to another carries _gl= in the destination address.
  • In Admin › Data display › DebugView (with Tag Assistant or debug mode on), the visit continues as one session across domains.

Sources