> For the complete documentation index, see [llms.txt](https://help.littledata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.littledata.io/advanced/developer/gtm-and-google-analytics-data-layer-for-shopify.md).

# GTM and Google Analytics data layer for Shopify

Use the events and data Littledata adds to the Google Tag Manager data layer on Shopify to trigger your own GTM tags, and see how an existing GTM setup works alongside Littledata.

When Littledata's Google Analytics 4 connection is on, Littledata's tracking script adds Shopify ecommerce events to the Google Tag Manager (GTM) data layer on your storefront. You can use these events to trigger your own GTM tags, read product and customer details in GTM variables, and send extra events to GA4.

This page explains what's in the data layer, how to use it in GTM, and how to run your existing GTM setup alongside Littledata without counting anything twice.

{% hint style="info" %}
The data layer events below come from Littledata's script on your online store pages. They are pushed when the [Google Analytics 4 connection](https://help.littledata.io/integrations/shopify-to-google-analytics.md) is set up and [Littledata's app embed](https://help.littledata.io/advanced/developer/littledata-app-embed-how-it-works.md) is turned on in your theme.
{% endhint %}

## How Littledata and GTM work together

Many larger stores already use GTM for marketing tags, A/B testing tools or their own analytics. Littledata doesn't replace your GTM container. Instead, the two split the work:

* **Littledata sends your ecommerce data to GA4 and your ad platforms.** Page views and product views come from the browser. Add to cart, checkout steps, purchases, refunds and subscription events come [server-side, straight from Shopify](https://help.littledata.io/integrations/shopify-to-google-analytics/how-it-works-shopify-to-ga4.md#server-side-events), so they aren't lost to ad blockers.
* **GTM runs your other tags.** It can use Littledata's data layer events as triggers and Littledata's product and customer data as variables.

To avoid counting events twice:

* **Don't send the same GA4 events from GTM.** If your container has a GA4 tag sending `page_view`, `view_item`, `add_to_cart` or `purchase` to the same GA4 property, pause those tags. Littledata already sends them.
* **Keep GTM for everything else.** Tags for other tools, and GA4 events Littledata doesn't send, can stay as they are.
* **If you'd rather send an event yourself,** turn it off in the GA4 [Event Editor](https://help.littledata.io/event-editor/enable-disable-events.md) so Littledata stops sending it.

For more on this, see the [Google Tag Manager FAQ](https://help.littledata.io/integrations/shopify-to-google-analytics/google-tag-manager-faq.md).

## Data layer events

These are the events Littledata pushes to `window.dataLayer`. Use the **GTM event** name in a GTM **Custom Event** trigger, and read the listed fields with **Data Layer Variables**.

| GTM event             | When it's pushed                                         | GA4 event Littledata sends | Data layer fields                            |
| --------------------- | -------------------------------------------------------- | -------------------------- | -------------------------------------------- |
| `pageview`            | Every page, when it's shown to the shopper               | `page_view`                | `page_title`, `page_location`                |
| `view_item_list`      | Products in a collection list scroll into view           | `view_item_list`           | `ecommerce.impressions` (a list of products) |
| `select_content`      | A shopper clicks a product in a list                     | `select_item`              | `ecommerce.click.products` (one product)     |
| `view_item`           | A product page loads                                     | `view_item`                | `ecommerce.detail.products` (one product)    |
| `product_image_click` | A shopper clicks a product image on a product page       | `select_content`           | `name` (image ID), `image_url`               |
| `share_product`       | A shopper clicks a social share button on a product page | `share`                    | `network`                                    |

When Littledata knows the shopper's email address, it also adds an `email` field to these events. It's an MD5 hash of the email, not the email itself.

### Things to know about these events

* **Page views:** a page view is only pushed when the page is actually shown. Pages opened in a background tab, or closed before they load, don't count.
* **Product list views:** a product counts as viewed when at least half of it is visible on screen. As shoppers scroll, events arrive in batches, one for each row of products that comes into view. Search results pages don't push `view_item_list`.
* **Product clicks:** the shopper's browser may move to the next page before your tags finish firing. Littledata doesn't delay the page to wait for them, so some click tags may not fire.
* **Turning off product list views:** if you turn off `view_item_list` in the GA4 Event Editor, the `view_item_list` data layer event stops too.

### Product fields

Each product in `ecommerce.impressions`, `ecommerce.click.products` and `ecommerce.detail.products` has these fields:

| Field                | What it holds                                                  |
| -------------------- | -------------------------------------------------------------- |
| `id`                 | The variant's SKU, or the Shopify product ID if there's no SKU |
| `name`               | Product title                                                  |
| `price`              | Variant price                                                  |
| `compare_at_price`   | Variant compare-at price                                       |
| `brand`              | Product vendor                                                 |
| `category`           | Product type                                                   |
| `variant`            | Variant title                                                  |
| `handle`             | Product handle                                                 |
| `shopify_product_id` | Shopify product ID                                             |
| `shopify_variant_id` | Shopify variant ID                                             |
| `shopify_sku`        | Variant SKU                                                    |
| `image_url`          | Main product image                                             |
| `tags`               | Product tags                                                   |
| `list_name`          | The list the product was shown or clicked in                   |
| `list_position`      | The product's position in that list                            |

## Events that aren't in the data layer

Add to cart, checkout steps, purchases, refunds and subscription events are tracked server-side, directly from Shopify. This makes them accurate and fast for GA4 and your ad platforms, but it means there's no data layer event to trigger a GTM tag on.

If another tool needs purchase data, check whether Littledata can send it to that tool directly. See [all destinations](https://help.littledata.io/integrations/overview.md).

## Use Littledata's data in GTM variables

Littledata also keeps store data in a `LittledataLayer` object on every page. You can read it in GTM with a **JavaScript Variable**.

| Variable                           | What it holds                                                                                                                                                                                    |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `LittledataLayer.ecommerce.detail` | The product on a product page, with the product fields above                                                                                                                                     |
| `LittledataLayer.customer`         | The logged-in customer: `id`, `email`, `firstName`, `lastName`, `phone`, `createdAt`, `address`, `customerLifetimeValue`, `purchaseCount` and `tags`. Only present when a customer is logged in. |
| `LittledataLayer.market`           | The current Shopify market's `id` and `handle`                                                                                                                                                   |
| `LittledataLayer.country`          | The shopper's country code                                                                                                                                                                       |
| `LittledataLayer.language`         | The storefront language code                                                                                                                                                                     |

{% hint style="success" %}
To read product data without writing JavaScript, use the **Shopify Variables by Littledata** template from the [GTM Community Template Gallery](https://tagmanager.google.com/gallery/#/owners/littledata/templates/gtm-variable). It returns product details for product and collection pages, plus your store's currency.
{% endhint %}

{% hint style="warning" %}
`LittledataLayer.customer` holds personal data, such as email address and phone number. Only send it to tools you're allowed to share it with, and follow your store's consent settings.
{% endhint %}

## Send extra events to GA4

Littledata loads Google's `gtag.js` library on every page of your store. You can call `gtag` from a GTM **Custom HTML** tag to send extra events to the same GA4 property. You don't need to wait for the library to load first.

For example, to track clicks on a navigation button:

```javascript
gtag('event', 'nav_button_click');
```

To add parameters:

```javascript
gtag('event', 'promo_click', {
  promo_name: 'BIG BANNER',
  promo_location: 'HOMEPAGE'
});
```

To see custom parameters in GA4 reports, register them as custom dimensions in GA4 under **Admin** > **Data display** > **Custom definitions**.

## Send extra events to Segment

If you use Littledata's Segment connection, Littledata loads Segment's Analytics.js on your store. Littledata sends its standard [browser events](https://help.littledata.io/integrations/shopify-to-segment/how-it-works.md#device-mode-events) for you, and you can add your own with `analytics.track`:

```javascript
analytics.track('nav_button_click');
```

## Related articles

* [Google Tag Manager FAQ](https://help.littledata.io/integrations/shopify-to-google-analytics/google-tag-manager-faq.md)
* [How it works: Shopify to Google Analytics](https://help.littledata.io/integrations/shopify-to-google-analytics/how-it-works-shopify-to-ga4.md)
* [Littledata's app embed](https://help.littledata.io/advanced/developer/littledata-app-embed-how-it-works.md)
* [Tracking plans and event schemas](https://help.littledata.io/advanced/developer/what-does-littledata-track.md)
