> For the complete documentation index, see [llms.txt](https://docs.rafflex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rafflex.io/helpful-info/what-google-analytics-tracks.md).

# What Google Analytics Tracks

Once Google Analytics is connected, RaffleX automatically sends a purchase event for every completed order. This page explains exactly what is sent, what is not, and how to turn it into useful sales r

Connecting Google Analytics is only the first step. The real value comes from understanding what your site sends back, so you can see genuine sales (not just visitor numbers) in your reports. This page explains what RaffleX sends to Google Analytics, what it does not send, how to add extra tracking if you want it, and the Google settings that turn the data into useful reports.

{% hint style="info" %}
Not connected yet? Start with [Google Analytics](/helpful-info/google-analytics.md) to create your account and add your Google tag. Come back here once that is done.
{% endhint %}

***

### Where your tracking tag lives

Google Analytics can only receive data if your Google tag is on your site. In RaffleX it goes in one place:

1. In your **admin panel**, find the **Content** group in the left-hand menu and click **Settings**.
2. In the Settings side menu, click **Advanced** (the page title reads **Advanced & Configuration**).
3. In the **Code Injection** section, paste your Google tag into the **Header Code** box.
4. Click **Save Settings**.

**Header Code** loads on **every page of your site**, including your checkout and the **Order Successful** page customers see after paying. That last page matters most, because it is where your sales data is sent from.

{% hint style="success" %}
This works whether you install a standard Google tag or a Google Tag Manager container. Both go in **Header Code**. If you use Google Tag Manager, its `<noscript>` snippet goes in the **Body Code** box just below. See [Advanced Settings](/additional-settings/settings/advanced-settings.md) for more on both boxes.
{% endhint %}

***

### What your Google tag tracks on its own

The moment your Google tag is installed, Google Analytics starts recording the basics by itself. RaffleX does not need to do anything for these:

* **Visitors and sessions**, including new and returning visitors.
* **Traffic sources**, such as Google search, Facebook, TikTok, email or people typing your address in directly.
* **Page views**, so you can see which competitions and pages are most popular.
* **Devices and locations**, such as mobile versus desktop, and which countries and towns visitors are in.
* **Enhanced measurement extras** (if you left it switched on), such as scrolling and clicks on links to other websites.

***

### What RaffleX sends automatically: purchases

When a customer completes an order and reaches the **Order Successful** page, RaffleX automatically sends a **purchase** event to Google Analytics. This is Google's standard ecommerce purchase event, so it slots straight into Google's built-in sales reports with no extra setup.

Every purchase event includes:

| Detail                   | What it contains                                                                                                                                                                                                                                                                            |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Transaction ID**       | Your order number. It is the number in the **#** column of your **Orders** list, and the customer sees it as **Order #** on their **Order Successful** page. Use it to match a sale in Google Analytics to the order in RaffleX.                                                            |
| **Value**                | The order total, after any discount code has been taken off.                                                                                                                                                                                                                                |
| **Currency**             | The currency set on your site, either **GBP** or **EUR**.                                                                                                                                                                                                                                   |
| **Tax** and **Shipping** | Always 0. Raffle tickets are not delivered, and RaffleX does not add tax or delivery figures.                                                                                                                                                                                               |
| **Items**                | One entry for each competition in the order, with the competition name, its ID, the number of tickets, the price per ticket and the currency. The number of tickets includes any free bonus tickets from a promotion, so tickets multiplied by price will not always equal the order value. |
| **Customer details**     | The customer's email address, phone number, name and address, laid out using the field names Google uses for enhanced conversions (explained further down this page).                                                                                                                       |

{% hint style="info" %}
**Each sale is sent once.** The purchase event fires the first time the customer sees the **Order Successful** page for that order. If they refresh the page or come back to it shortly after, the sale is not sent again, so your revenue figures stay accurate.
{% endhint %}

#### Why Google Analytics may show fewer sales than RaffleX

Google Analytics and your RaffleX figures will rarely match exactly. This is normal, and it happens for a few reasons:

* **The sale is sent from the customer's browser.** If a customer pays and then closes the tab before the **Order Successful** page loads, the order is still completed in RaffleX, but Google Analytics never hears about it.
* **Ad blockers and privacy settings.** Some browsers and extensions block Google Analytics completely, so those visits and sales are not recorded.
* **Cookie consent.** If your site asks visitors for cookie consent and they decline analytics, Google may not record them, or may only estimate their activity.

Treat Google Analytics as the place to see **trends and where sales come from**. For your true sales and revenue figures, always use the built-in [Analytics](/helpful-info/analytics.md) section and your **Orders** list in RaffleX.

{% hint style="info" %}
Orders that cost the customer nothing, such as entries into a free competition, also reach the **Order Successful** page, so they show up in Google Analytics as purchases with a value of zero. Bear this in mind when you look at your number of purchases.
{% endhint %}

***

### What is not tracked automatically

It helps to know the limits so your reports do not surprise you.

* **Add to cart** is not sent to Google Analytics by default. You can add it yourself with the short script below.
* **Viewing a competition, starting checkout and other checkout steps** are not sent to Google Analytics as ecommerce events. Visits to those pages still appear as normal page views.
* **Sign ups and logins** are not sent to Google Analytics as events.

Out of the box, **purchase** is the only sales event RaffleX sends to Google Analytics.

#### Add "add to cart" tracking

Every time a customer adds tickets using the ticket selector on a competition page, RaffleX announces it inside the browser. The script below listens for that announcement and passes it to Google Analytics as Google's standard `add_to_cart` event. Once it is live, you can see how many people add tickets but do not go on to buy.

1. In your admin panel, open **Settings**, then click **Advanced**.
2. In the **Code Injection** section, click at the very end of the code in the **Header Code** box, **below** your Google tag, and press **Enter** to start a new line.
3. Paste the script below.
4. If your site uses euros, change `'GBP'` to `'EUR'` in the script.
5. Click **Save Settings**.

```html
<!-- Google Analytics: add to cart -->
<script>
document.addEventListener('livewire:init', () => {
    Livewire.on('addtobasket', (event) => {
        if (typeof gtag === 'function') {
            var price = parseFloat(event.productPrice);
            gtag('event', 'add_to_cart', {
                currency: 'GBP',
                value: parseFloat((price * event.tickets).toFixed(2)),
                items: [{
                    item_id: event.productId.toString(),
                    item_name: event.content,
                    quantity: event.tickets,
                    price: price
                }]
            });
        }
    });
});
</script>
```

{% hint style="warning" %}
**The script must sit below your Google tag** in **Header Code**, because it relies on the Google tag being there. The currency code must be in capitals and must match your site's currency (**Settings**, then **Checkout**).
{% endhint %}

A couple of things to keep in mind:

* It fires when tickets are added using the ticket selector on a competition page. It does **not** fire for tickets added through the upsell popup at checkout (see [Upsell](/marketing/website-tools/upsell.md)), or through the quick add buttons that some competition card designs and homepage blocks offer. This means your add to cart figure may be lower than the true number of times tickets go into baskets.
* If you use Google Tag Manager rather than a Google tag, this script will not find `gtag`. Set up add to cart tracking inside Tag Manager instead, or ask whoever manages your Tag Manager to adapt it.

Want to send add to cart and purchase events to TikTok or Google Ads as well? See [Conversion Event Tracking](/advanced/conversion-event-tracking.md) for ready-made snippets.

***

### The data layer (for the technically minded)

This section is optional. Skip it if you are using the standard Google tag and just want the reports to work.

RaffleX publishes each purchase to the browser **data layer** (`window.dataLayer`), the standard channel that Google Tag Manager reads from. On the **Order Successful** page it first clears any previous ecommerce data (as Google recommends), then pushes an event named `purchase` with an `ecommerce` object containing these fields:

| Field               | Meaning                                                                                                                                        |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `transaction_id`    | The order number (the **#** column in your **Orders** list)                                                                                    |
| `value`             | The order total after any discount, as a number                                                                                                |
| `currency`          | `GBP` or `EUR`                                                                                                                                 |
| `tax`               | Always `0`                                                                                                                                     |
| `shipping`          | Always `0`                                                                                                                                     |
| `items`             | A list with one entry per competition in the order                                                                                             |
| `items[].item_name` | The competition title                                                                                                                          |
| `items[].item_id`   | The competition ID                                                                                                                             |
| `items[].quantity`  | The number of tickets, including any free bonus tickets from a promotion                                                                       |
| `items[].price`     | The price per ticket                                                                                                                           |
| `items[].currency`  | `GBP` or `EUR`                                                                                                                                 |
| `user_data`         | The customer's `email_address`, `phone_number` and `address` (`first_name`, `last_name`, `street`, `city`, `region`, `postal_code`, `country`) |

If a standard Google tag (`gtag`) is on the page, RaffleX also sends the same `purchase` event through it directly. So the sale reaches Google whether you installed Google Analytics on its own or through Google Tag Manager.

#### Setting up purchases in Google Tag Manager

If you use Google Tag Manager, you need to tell it what to do with the `purchase` event:

1. In Google Tag Manager, go to **Triggers** and click **New**.
2. Choose **Custom Event** as the trigger type, enter `purchase` as the **Event name**, and save it with a clear name such as "RaffleX purchase".
3. Go to **Tags** and click **New**.
4. Choose **Google Analytics: GA4 Event**, enter your Measurement ID (it starts with **G-**) and set the **Event Name** to `purchase`.
5. Under **More Settings**, open **Ecommerce**, tick **Send Ecommerce data** and choose **Data Layer** as the data source.
6. Set the trigger to the "RaffleX purchase" trigger you just made, then save.
7. Use Tag Manager's **Preview** mode with a test order to check the tag fires, then click **Submit** to publish.

{% hint style="warning" %}
If you use Google Tag Manager, do not also add a separate Google tag for the same Google Analytics property. With both in place, each purchase is recorded twice.
{% endhint %}

{% content-ref url="/pages/2rhzTztqN3RkgA0N7k8S" %}
[Conversion Event Tracking](/advanced/conversion-event-tracking.md)
{% endcontent-ref %}

***

### Improve your Google Analytics tracking

Once purchases are flowing, a few Google Analytics settings turn raw data into something genuinely useful.

1. **Mark purchase as a key event.** In Google Analytics, click **Admin** (the cog in the bottom left), then **Events** (under **Data display**), and mark `purchase` as a key event. "Key event" is Google's newer name for a conversion. This lets you see which channels and campaigns actually drive sales, not just clicks. The `purchase` event appears in the list once at least one sale has come through, which can take up to a day.
2. **Check your Monetisation reports.** Open **Reports**, then **Monetisation**, then **Ecommerce purchases**. You will see revenue, your best-selling competitions and the number of tickets sold, pulled straight from your live sales.
3. **Look at sales by traffic source.** Open **Reports**, then **Acquisition**, then **Traffic acquisition**. Add the purchase revenue column (if it is not already shown) to see which sources bring in money, not just visitors.
4. **Add UTM tags to your marketing links.** UTM tags tell Google Analytics exactly where a visitor came from, so a sale can be traced back to the right email, post or advert. See [UTM Tags](/helpful-info/utm-tags.md).
5. **Consider enhanced conversions.** Google's **enhanced conversions** feature uses customer contact details to match sales back to the right ad more accurately. Google turns the details into a scrambled code (a "hash") before using them. RaffleX includes the customer's contact details with each purchase, so the information is there for Google to use. Whether Google picks it up depends on how your tag is set up, so switch on **user-provided data collection** in your Google Analytics data collection settings (or enhanced conversions in Google Ads), follow Google's on-screen guidance, and check Google's diagnostics afterwards to confirm the details are being received. If you use Google Tag Manager, you can point its user-provided data settings at the `user_data` fields described in the data layer section above.

{% hint style="warning" %}
**Personal data.** The purchase event includes customer contact details for enhanced conversions. Make sure your privacy policy and cookie consent cover analytics and advertising before you rely on it, so you stay compliant with UK and EU data protection rules. If you are unsure, take advice.
{% endhint %}

***

### Quick troubleshooting

| What you see                   | What to check                                                                                                                                              |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| No visitors at all             | Is your Google tag still in **Header Code** on the **Advanced** settings page? Are you looking at the right property? Try a browser without an ad blocker. |
| Visitors, but no purchases     | Purchases only send when a customer reaches the **Order Successful** page. Place a small test order yourself and watch **Reports**, then **Realtime**.     |
| Purchases recorded twice       | You probably have Google Analytics installed twice (for example a Google tag **and** Google Tag Manager, or two copies of the same tag). Remove one.       |
| Revenue in the wrong currency  | Check your Google Analytics property currency matches your site currency (**Settings**, then **Checkout**).                                                |
| Fewer sales than RaffleX shows | This is expected. See "Why Google Analytics may show fewer sales than RaffleX" above.                                                                      |

You can review your sales inside RaffleX at any time without Google Analytics. See the built-in [Analytics](/helpful-info/analytics.md) section for revenue and order figures, and the **Orders** list for each individual order.
