---
title: "From Classic Analytics to Google Analytics 4"
description: "Remove _setDomainName, _link and _linkByPost code with example-petstore.com, install the Google tag and set up cross-domain measurement in GA4."
url: https://example-petstore.com/guides/google-analytics-cross-domain
language: en
---

# 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.** Universal Analytics stopped processing data on 1 July 2023 and was switched off 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 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
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** › **List unwanted referrals** (up to 50 per stream). Matching visits then continue the existing session instead of starting a new one.

## 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** › **DebugView** (with Tag Assistant or debug mode on), the visit continues as one session across domains.

## Sources

- [Tracking Multiple Domains (Classic Analytics, 2009 snapshot)](http://web.archive.org/web/20090327154737/http://code.google.com:80/apis/analytics/docs/tracking/gaTrackingSite.html) Google Code via the Wayback Machine
- [Tracking Multiple Domains (Classic Analytics, 2013 snapshot)](http://web.archive.org/web/20130115024413/https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite) Google Developers via the Wayback Machine
- [Universal Analytics has been replaced by Google Analytics 4](https://support.google.com/analytics/answer/11583528) Google Analytics Help
- [Measure activity across multiple domains](https://developers.google.com/tag-platform/devguides/cross-domain) Google Tag Platform
- [Set up cross-domain measurement](https://support.google.com/analytics/answer/10071811) Google Analytics Help
- [Identify unwanted referrals](https://support.google.com/analytics/answer/10327750) Google Analytics Help
- [Google tag settings in Tag Manager](https://support.google.com/tagmanager/answer/12131703) Tag Manager Help
- [Monitor events in DebugView](https://support.google.com/analytics/answer/7201382) Google Analytics Help
