# Integrations

TryFast works with the tools already on your page: it tells your tag manager and analytics which variation a visitor saw, it listens to your cookie banner, and any script can react to its window events.

## Google Tag Manager and the data layer

When the project setting **dataLayer events** is on (the default) and your page has a `window.dataLayer` array, TryFast pushes:

```js
// when a visitor enters an experiment (once per experiment per page view)
{event: "tryfast_exposure", tryfast_experiment: "free-shipping-headline", tryfast_variation: "b"}

// when a goal fires
{event: "tryfast_conversion", tryfast_goal: "purchase"}
```

TryFast never creates `window.dataLayer`; without it nothing is pushed. Nothing is pushed before consent, and never in the `exempt` consent mode ([Privacy and consent](privacy-and-consent.md)).

### Send experiments to Google Analytics 4 through Tag Manager

1. In Tag Manager, create two **Data Layer Variables**: `tryfast_experiment` and `tryfast_variation`.
2. Create a trigger of type **Custom Event** with the event name `tryfast_exposure`.
3. Create a **Google Analytics: GA4 Event** tag named for example `experiment_exposure`, with the event parameters `experiment` = `{{tryfast_experiment}}` and `variation` = `{{tryfast_variation}}`, fired by that trigger.
4. In GA4, register the two parameters as custom dimensions to compare segments.

The numbers in GA4 will differ from TryFast's: GA4 counts sessions and its own consent and filtering, while TryFast counts each visitor once from their first exposure, with bots and test traffic removed. Use TryFast's results for the decision and GA4 to explore.

## Window events

Every page with the snippet dispatches `tryfast:ready`, `tryfast:exposure`, `tryfast:conversion` and `tryfast:aborted` on `window` ([JavaScript API](javascript-api.md#window-events)). For example, to tag your own analytics or session replay tool:

```js
window.addEventListener("tryfast:exposure", function (e) {
  myAnalytics.track("Experiment viewed", {
    experiment: e.detail.experiment.key,
    variation: e.detail.variation.key
  });
});
```

## Consent banners

With the default consent mode, TryFast waits until your cookie banner says yes. Connect it by calling `consent(true)` when the visitor accepts, and `consent(false)` only when they actively decline or withdraw (it clears TryFast's storage). Use the queue form so the call works even when your banner runs before the TryFast script:

```js
window.tryfast = window.tryfast || [];
window.tryfast.push(["consent", true]);
```

`consent(true)` is remembered in the visitor's browser, so later pages apply experiments before your banner script has loaded. Assign TryFast to the category your banner uses for statistics, analytics or performance, never to strictly necessary cookies, and list it in your banner's services so visitors can see it.

Ready-made recipes, each a few lines to paste after your banner's script, are in [Privacy and consent](privacy-and-consent.md#connect-your-cookie-banner):

- [Cookiebot](privacy-and-consent.md#cookiebot)
- [Usercentrics](privacy-and-consent.md#usercentrics)
- [OneTrust](privacy-and-consent.md#onetrust)
- [Didomi](privacy-and-consent.md#didomi)
- [IAB TCF v2.2 banners](privacy-and-consent.md#iab-tcf-v22-banners)
- [Google Tag Manager and other banners](privacy-and-consent.md#google-tag-manager-and-other-banners)

Testing without a banner? Open your site and run `tryfast.push(["consent", true])` in the browser console.

## Not yet available

Native connections to analytics tools, webhooks and server-side conversions (sending a conversion from your backend) are planned. Until then, use the data layer, the window events, and `tryfast.track()` on the confirmation page.
