Cloudflare Docs
Zaraz
Visit Zaraz on GitHub
Set theme to dark (⇧+D)

Data layer compatibility mode

Cloudflare Zaraz offers backwards compatibility with the dataLayer function found in tag management software, used to track events and other parameters. This way you can keep your current implementation and Cloudflare Zaraz will automatically collect your events.

To keep the Zaraz script as small and fast as possible, the data layer compatibility mode is disabled by default. To enable it:

  1. Go to Zaraz > Settings.
  2. Enable the Data layer compatibility mode toggle. Refer to Zaraz settings for more information.

Using the data layer with Zaraz

After enabling the compatibility mode, Zaraz will automatically translate your dataLayer.push calls to zaraz.track, so you can keep using the dataLayer.push function to send events from the browser to Zaraz.

Events will only be sent to Zaraz if your pushed object includes an event key. The eventkey is used as the name for the Zaraz event. Other keys will become part of the eventProperties object. The following example shows how a purchase event will be sent using the data layer to Zaraz — note that the parameters inside the object depend on what you want to track:

dataLayer.push({
event: 'purchase',
price: '24',
currency: 'USD',
transactionID: '12345678',
});

Cloudflare Zaraz then translates the dataLayer.push() call to a zaraz.track() call. So, dataLayer.push({event: "purchase", price: "24", "currency": "USD"}) is equivalent to zaraz.track("purchase", {"price": "24", "currency": "USD"}).

Because Zaraz converts the dataLayer.push call to zaraz.track, creating a trigger based on dataLayer.push calls is the same as creating triggers for zaraz.track. As an example, the trigger below would match the above dataLayer.push call because it matches the event name ({{ client.__zarazTrack }}) with purchase.

Rule typeVariable nameMatch operationMatch string
Match rule{{ client.__zarazTrack }}Equalspurchase

We do not recommend using dataLayer. However, as many websites employ it, Cloudflare Zaras has this automatic translation layer that converts it to zaraz.track().