# Add a Meta pixel to your stories without Tag Manager

Source: https://knowledge.intractive.app/en/articles/meta-adding-a-meta-pixel-without-tag-manager

You can run a complete Meta pixel in your stories without a Tag Manager container. One script in the project's **Footer code** field sends the story events, scoring and consent, and we add it for you when you send us a message in the chat.

## Choose a route

| Consideration | Tag Manager | Footer script |
| --- | --- | --- |
| Time to first event | Slower: you need access to a Tag Manager container first | Live from the next page load after we save the script |
| Who can change it later | Your own marketers, in your Tag Manager account | Only Intractive, through a message in the chat |
| Debugging | Tag Assistant shows every tag and why it did or didn't fire | Browser console only |
| Several destinations | Add a tag | Edit the code |
| Versioning and rollback | Built in | None |

Use Tag Manager when you want to own your tracking, when Google Analytics is in scope too, or when the campaign will run long enough for someone to want changes.

Use the footer script when you have no container and don't want one, when the campaign is short and the events are already agreed, or when you want it live from the next page load after we save it. It sends the same five events a Tag Manager setup would. In return, debugging is harder and you can't change it yourself.

### The built-in Meta pixel

There's a third route. Intractive can add your Meta pixel ID directly under **Tools** on **Project settings** > **Tracking & scripts**, with no Tag Manager and no script. Send us a message in the chat and we'll set it up.

\[screenshot: Project settings, Tracking & scripts page with the Tools section\]

In stories, the built-in pixel sends `PageView` when a story opens, and `StoryStart`, `StoryProgress`, `StoryComplete` and `OutboundClick` as custom events. On the project's pages it sends `PageView`, `ViewContent`, `Download` and `OutboundClick`, and the page's conversion. In stories, only `StoryComplete` has the same name as one of the five events in this article. On the project's pages, `ViewContent` does too. Use the footer script when you need the five events in this article. We'll remove the built-in pixel for you when needed.

Intractive doesn't show a cookie banner, so consent for the built-in pixel is your responsibility.

If you switch to the footer script, send us a message in the chat and we'll remove the pixel ID under **Tools**. With the same pixel ID in both, `PageView` is sent twice. In stories, the other events have different names, so they arrive as two separate sets.

> [!WARNING]
> Don't run Meta tags in Tag Manager and the footer script on the same project. If a project has Meta tags in Tag Manager and the footer script, every event is sent twice to the same pixel. Neither sends an `event_id`, so Meta counts both as real. We measured this with Tag Manager and the footer script together: a single story start produced two `ViewContent` events. Pick one route and remove the other.

## The five events

The footer script sends the same five events in every story. Keep this set fixed: stories on Intractive's own domain share one domain, and Meta limits configurable events per domain, so every customer on that domain shares the limit. A project with a **Custom domain** serves its stories from that domain. New event names for each project use up a shared allowance and make ad accounts inconsistent.

| Event | Meta type | Fires on | What it's for |
| --- | --- | --- | --- |
| `ViewContent` | standard | Story start | Audience seed, and the denominator for every drop-off number |
| `StoryHalfway` | custom | Reached 50% | Engagement. Tells you whether the ad or the story is the problem |
| `StoryComplete` | custom | Reached 100% | Retargeting people who finished but didn't click |
| `Lead` | standard | Outbound link click | The conversion. Optimise campaigns on this |
| `QualifiedCandidate` | custom | Score reached, or segment assigned | Mid-funnel optimisation once volume allows |

`ViewContent` and `Lead` are Meta standard events. You can select them as campaign objectives with no extra setup. The other three are custom events: create a Custom Conversion for each in Events Manager before you optimise toward it.

`Lead` means the visitor clicked through to the destination. The application itself happens in your ATS, out of reach of a pixel. Be precise about this when you report, or the number will seem to promise more than it supports.

## Optional: scoring and segments

You can profile visitors in two ways. Both are optional. Set up neither and you get four clean events.

Scoring measures how interested a person is. The story adds points as people answer. When the total crosses a threshold, `QualifiedCandidate` fires and the score travels as `value`. That value is what makes value-based lookalike audiences possible later.

Segments record which role fits a person. The story writes a category into a variable. From the moment it's known, that category travels as a `segment` parameter on every event.

Send categories as a parameter, never as event names. Avoid event names such as `FitEngineering` or `FitWarehouse`. One event carrying `segment: "engineering"` gives you any number of segments inside the fixed set of five. Build one Custom Conversion per segment in Events Manager, and each segment becomes its own audience.

> [!WARNING]
> Keep segment values to neutral role labels, such as `engineering`, `warehouse` or `customer-support`. Never use age, nationality, parental status, salary expectation, language or accessibility needs. A segment is inferred personal data about a person, sent to an advertising platform, in a recruitment context. Anything that stands in for a protected characteristic is a problem under Meta's terms and under employment law.

## Set up the footer script

### Before you start

- The Meta pixel ID you want to send to.
- A message to us in the chat. The **Footer code** field isn't self-service: we set it for you. We first check whether Tag Manager would do the job. We also talk through privacy and consent with you. A bad tag can break the story for every visitor.

Consent for this script is your responsibility under GDPR, ePrivacy and similar rules. Intractive doesn't show a cookie banner for tags loaded through **Footer code**. Footer code loads on every visit, so the script has to check consent itself. The project's **Strict** setting under **Remember visitors** doesn't apply to them either.

### Steps

1. Copy the snippet from the section below.
2. Set `pixelId` in the `CONFIG` block to your Meta pixel ID.
3. Optional: change `currency` if you report values in a currency other than euros.
4. Optional: for scoring, set `score.variable` to the name of your scoring variable, without the `@`, and `score.threshold` to the score that counts as qualified. To switch scoring off, set `variable: null`.
5. Optional: for segments, set `segment.variable` to the name of the variable that holds the category, without the `@`, for example `'best_fit'`. The snippet adds the `@`.
6. Optional: set `trackHalfway` to `false` if you don't want `StoryHalfway`.
7. Optional: set `requireConsent` to `true` if your consent tool should decide when tracking starts. Nothing is sent until your consent tool calls `window.intractiveMetaConsent()`. At that point, everything the visitor already earned is replayed, not lost.
8. Send the snippet to us in the chat.

We add it to the **Footer code** field under **Project settings** > **Tracking & scripts** > **Custom code**. The script is injected at the end of the page, after the story has rendered. It applies to every story in the project, every QR code and every custom domain entry point.

Don't send Meta's base pixel code from Events Manager as well. The snippet already includes it, and adding both starts the pixel twice. You can skip Meta's noscript image fallback too. It exists for visitors with JavaScript turned off, and a story is a JavaScript app, so those visitors see nothing to track.

### The snippet

The snippet is already wrapped in script tags. The **Footer code** field accepts only top-level `<script>` and `<noscript>` tags, with no `on*` handlers and no `javascript:` URLs. Only the settings inside `CONFIG` change per project. Everything below it is the same for every story.

```javascript
<script>(function () {

  /* CONFIG - edit this block only */

  var CONFIG = {
    pixelId:  '000000000000000',                            // client's pixel ID
    currency: 'EUR',
    score:    { variable: 'intent_score', threshold: 60 },  // or variable: null
    segment:  { variable: null },                           // or e.g. 'best_fit'
    trackHalfway:   true,
    requireConsent: false
  };

  /* END CONFIG - nothing below needs editing */

  var ctx = { story_id: null, session_id: null },
      fired = {}, started = false, score = null,
      segment = null, enabled = true,
      consent = !CONFIG.requireConsent;

  function readVar(vars, name) {
    if (!vars || !name) return undefined;
    return vars['@' + name];        // story variables carry an @ prefix
  }

  function send(key, name, type, extra) {
    if (fired[key] || !enabled || !consent) return;
    if (typeof fbq !== 'function') return;
    fired[key] = true;
    var p = { story_id: ctx.story_id, session_id: ctx.session_id };
    if (segment) p.segment = segment;
    if (extra) for (var k in extra) p[k] = extra[k];
    fbq(type, name, p);
  }

  function qualify() {
    var byScore = CONFIG.score && CONFIG.score.variable &&
                  score !== null && score >= CONFIG.score.threshold,
        bySeg   = CONFIG.segment && CONFIG.segment.variable && segment;
    if (!byScore && !bySeg) return;
    send('qualified', 'QualifiedCandidate', 'trackCustom',
         score === null ? null : { value: score, currency: CONFIG.currency });
  }

  function handle(o) {
    if (!o || !o.event) return;
    if (o.event === 'disableTracking') { enabled = false; return; }
    if (o.event === 'enableTracking')  { enabled = true;  return; }

    if (o.storyId)   ctx.story_id   = o.storyId;
    if (o.sessionId) ctx.session_id = o.sessionId;

    if (o.event === 'intractiveVariablesUpdated') {
      var s = Number(readVar(o.variables, CONFIG.score && CONFIG.score.variable));
      if (!isNaN(s)) score = s;
      var g = readVar(o.variables, CONFIG.segment && CONFIG.segment.variable);
      if (g) segment = String(g);
      if (started) qualify();
      return;
    }

    if (o.event === 'intractiveStoryMilestone') {
      // Milestones fire once per playthrough and a resumed session does not
      // repeat the ones it already passed, so a reload sends nothing.
      var m = Number(o.milestone);
      if (m === 0) { started = true; send('view', 'ViewContent', 'track'); return; }
      if (CONFIG.trackHalfway && m === 50) send('half', 'StoryHalfway',  'trackCustom');
      if (m === 100)                       send('done', 'StoryComplete', 'trackCustom');
      return;
    }

    if (o.event === 'intractiveOutboundLink' && started) {
      send('lead', 'Lead', 'track', {
        link_url: o.url,
        value:    score === null ? 0 : score,
        currency: CONFIG.currency
      });
    }
  }

  if (!window.fbq) {
    !function (f, b, e, v, n, t, s) {
      if (f.fbq) return; n = f.fbq = function () {
        n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
      };
      if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0';
      n.queue = []; t = b.createElement(e); t.async = !0; t.src = v;
      s = b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t, s);
    }(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
  }

  fbq('init', CONFIG.pixelId);
  if (consent) fbq('track', 'PageView');

  window.intractiveMetaConsent = function () {
    if (consent) return;
    consent = true;
    fbq('track', 'PageView');
    for (var i = 0; i < dl.length; i++) handle(dl[i]);
  };

  var dl = window.dataLayer = window.dataLayer || [];
  for (var i = 0; i < dl.length; i++) handle(dl[i]);
  var push = dl.push;
  dl.push = function () {
    var r = push.apply(dl, arguments);
    for (var j = 0; j < arguments.length; j++) handle(arguments[j]);
    return r;
  };

})(); </script>

```

### What the snippet already handles

- Reloading a finished story sends only `PageView`. See [Why completions get over-counted](https://knowledge.intractive.app/en/articles/meta-why-completions-get-over-counted) for why this matters.
- Each event fires at most once per page load.
- A resumed playthrough sends no start mark, so it sends no `ViewContent`. `StoryHalfway` and `StoryComplete` don't wait for it and still fire.
- When one step crosses several marks, only the highest is sent. A jump from 25% straight to 100% sends `StoryComplete` and no `StoryHalfway`.
- Late consent is handled when you set `requireConsent` to `true` (step 7).

## Check that it works

The browser console shows what the browser actually sent, with no reporting delay. Check it first, every time, before you look in Events Manager. The footer script also runs on builder previews and for signed-in editors, so your own test visits send events to the pixel. The built-in pixel skips builder visits.

1. Open the story in a private window. Use a story you haven't finished in that browser.
2. Open the browser console.
3. Run this code:

   ```javascript
   performance.getEntriesByType('resource')
     .filter(e => e.name.includes('/tr'))
     .map(e => new URL(e.name).searchParams.get('ev'))
   ```

On a fresh start you see `["PageView", "ViewContent"]`, each exactly once. If an event shows up twice, the pixel is loaded twice. Check whether Tag Manager is also running Meta tags on this project. If only `PageView` shows up twice, the same pixel ID is probably also set under **Tools**.

\[screenshot: browser console showing PageView and ViewContent once each\]

To confirm the right pixel is live, run:

```javascript
Object.keys(window.fbq.instance.pixelsByID)

```

## Reading Events Manager without being misled

Events Manager is slow, and its default view hides today. We've lost time to each of these.

| Trap | What to do |
| --- | --- |
| The date range ends yesterday | The default range leaves out today. A brand-new pixel only has today's data, so it always looks dead. Set the range to **Today** before you conclude anything. |
| New events take hours to show up | Meta says 30 minutes. For an event name or a dataset it has never seen, it has taken several hours, and then everything appeared at once. Check the console and wait. |
| The overview contradicts itself | We've seen the table report no activity while its own chart plotted dozens of events. When they disagree, trust neither. Go back to the console check. |
| 'Finish setting up Meta Pixel · 0% complete' | This is an onboarding checklist. It stays at 0% until Meta processes your first events. It doesn't mean the pixel is broken. |

\[screenshot: Events Manager overview with the date range set to Today\]

## Next

- [Why completions get over-counted](https://knowledge.intractive.app/en/articles/meta-why-completions-get-over-counted)
- [Connect story tracking to Google Tag Manager](https://knowledge.intractive.app/en/articles/meta-story-events-with-google-tag-manager)
