> For the complete documentation index, see [llms.txt](https://docs.zigpoll.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zigpoll.com/integrations/intelligems.md).

# Intelligems

Tag survey responses with the Intelligems experiment and test group each respondent saw

If you run A/B tests with [Intelligems](https://www.intelligems.io/), you can record which test group each respondent was in alongside their survey response. That lets you compare how customers in each variant answered — for example, whether shoppers who saw a new product page layout report a different reason for buying than shoppers who saw the control.

The integration is a short snippet you add to your Shopify theme. Nothing needs to be turned on in Zigpoll or in Intelligems.

## How it works

Intelligems puts a JavaScript object, `window.igData`, on every page it runs on. The snippet waits for Intelligems to load, reads the name of each experiment the visitor is in and the name of the test group they were assigned to, and hands them to Zigpoll in two ways:

* **Storefront surveys** — it adds them to [`window.Zigpoll.metadata`](/embed/poll-metadata.md), which Zigpoll saves with every answer.
* **Checkout and thank-you page surveys** — it saves them as hidden cart attributes starting with `_zigpoll_`. Zigpoll's checkout extension copies those attributes onto the response.

Intelligems only reports the experiments that run on the page the visitor is currently viewing. A test that runs on product pages is invisible on the homepage or the thank-you page, so the snippet remembers each assignment in the visitor's browser and keeps sending it on later pages.

Each experiment becomes one metadata field named `intelligems_` followed by the experiment name, and the value is the test group name:

| Intelligems experiment  | Test group      | Zigpoll metadata                                     |
| ----------------------- | --------------- | ---------------------------------------------------- |
| PDP Hero Image          | Lifestyle Photo | `intelligems_pdp_hero_image: Lifestyle Photo`        |
| Free Shipping Threshold | Control Group   | `intelligems_free_shipping_threshold: Control Group` |

## Setup

#### Step #1: Add the snippet to your theme

1. In Shopify, go to **Online Store → Themes**.
2. Next to your live theme, click **⋯ → Edit code**.
3. Under **Layout**, open `theme.liquid`.
4. Paste the snippet below just above the closing `</head>` tag, then click **Save**.

```html
<script>
/* Zigpoll + Intelligems: tag survey responses with the visitor's test groups */
(function () {
  var STORAGE_KEY = 'zigpoll_intelligems';
  var MAX_AGE = 30 * 24 * 60 * 60 * 1000; // forget experiments not seen for 30 days

  function toKey(name) {
    return 'intelligems_' + String(name).toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '').slice(0, 60);
  }

  function sync() {
    var user = window.igData && window.igData.user;
    if (!user) { return; }

    var now = Date.now();
    var seen = {};
    try { seen = JSON.parse(localStorage.getItem(STORAGE_KEY)) || {}; } catch (e) {}

    /* Intelligems only lists the experiments that run on the current page,
       so remember the ones seen on earlier pages (e.g. a product page test). */
    (user.getExperiments() || []).forEach(function (experiment) {
      var group = user.getTestGroup(experiment.id);
      if (group) { seen[experiment.id] = { name: experiment.name, group: group.name, at: now }; }
    });

    var fields = {};
    Object.keys(seen).forEach(function (id) {
      if (now - seen[id].at > MAX_AGE) { delete seen[id]; return; }
      fields[toKey(seen[id].name)] = seen[id].group;
    });
    try { localStorage.setItem(STORAGE_KEY, JSON.stringify(seen)); } catch (e) {}
    if (!Object.keys(fields).length) { return; }

    /* 1. Surveys on your storefront */
    window.Zigpoll = window.Zigpoll || {};
    window.Zigpoll.metadata = window.Zigpoll.metadata || {};
    Object.keys(fields).forEach(function (key) { window.Zigpoll.metadata[key] = fields[key]; });

    /* 2. Checkout and thank-you page surveys, which read _zigpoll_ cart attributes */
    var root = (window.Shopify && window.Shopify.routes && window.Shopify.routes.root) || '/';
    fetch(root + 'cart.js', { credentials: 'same-origin' })
      .then(function (res) { return res.json(); })
      .then(function (cart) {
        var current = cart.attributes || {};
        var attributes = {};
        var changed = false;
        Object.keys(fields).forEach(function (key) {
          attributes['_zigpoll_' + key] = fields[key];
          if (current['_zigpoll_' + key] !== fields[key]) { changed = true; }
        });
        if (!changed) { return; }
        return fetch(root + 'cart/update.js', {
          method: 'POST',
          credentials: 'same-origin',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ attributes: attributes })
        });
      })
      .catch(function () {});
  }

  if (window.igData) { sync(); } else { window.addEventListener('ig:ready', sync); }
})();
</script>
```

{% hint style="info" %}
The snippet waits for Intelligems to finish loading, so it works wherever you place it in the page — before or after the Intelligems and Zigpoll scripts. It only updates the cart when a test group has changed, not on every page view.
{% endhint %}

#### Step #2: Check that it's working

1. Open your store on a page where an Intelligems experiment is running. Intelligems preview links work too.
2. Open your browser's developer console and run `window.Zigpoll.metadata`. You should see an `intelligems_…` field for each experiment you're in.
3. Visit `/cart.js` on your store. Under `attributes` you should see the same fields, starting with `_zigpoll_intelligems_`.
4. Submit a test response and open it on the survey's **Responses** page. The `intelligems_…` fields appear in the response's metadata.

## Using the data

Once responses carry test group metadata, you can compare variants anywhere Zigpoll lets you filter by metadata:

* **Filter results by test group** — on the **Dashboard**, **Answers**, or **Charts** page, click the filter icon, choose the `intelligems_…` field under **Custom**, and pick a test group. Every tally and chart recalculates for that group. See [Filtering results by metadata](/analytics-ai-and-reporting.md#filtering-results-by-metadata).
* **Export** — the fields are included as columns in CSV exports and Google Sheets syncs, so you can pivot answers by test group in your own tools.
* **Match to orders** — post-purchase responses are already linked to their Shopify order, so you can line them up with Intelligems' own order export.

## Which surveys are tagged

| Survey                                                                   | Tagged?                                                                         |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
| Surveys shown on your storefront                                         | Yes                                                                             |
| Checkout and thank-you page surveys                                      | Yes, as long as the shopper visited a page with the snippet before checking out |
| Email, SMS, and survey link surveys                                      | No — they are answered outside the shopper's browsing session                   |
| Surveys with [Anonymous mode](/polls/display-rules.md#anonymous-mode) on | No — anonymous surveys don't store metadata                                     |

## Good to know

* **Renaming an experiment** in Intelligems starts a new metadata field, since the field name comes from the experiment name. Responses collected before the rename keep the old field.
* **Ended experiments** stop being recorded 30 days after the visitor last saw them on a page where the experiment ran. To change that window, edit `MAX_AGE` in the snippet.
* **Testing in preview mode** tags your own browser with the previewed group. To clear it, run `localStorage.removeItem('zigpoll_intelligems')` in the console.
* **Shoppers who skip your storefront**, for example by following a direct checkout link, won't have a test group on their post-purchase response. Intelligems still adds its own `igTestGroups` attribute to the order, which holds the test group ID.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zigpoll.com/integrations/intelligems.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
