# MTAM

_Tba._

## Datalayer

MTAM watches `window.dataLayer`. The top-level `eventType` field routes `identify`, `page`, and `track` operations. Include an `event` label to make each push easy to inspect; the agent does not use that label for routing. The track event name is in `trackEventName`.

The routing fields are top-level. Identify traits are read from the top level; track properties are supplied as a JSON object in `properties`.

### Identify

```js
window.dataLayer.push({
  event: "homepageProfileUpdated",
  eventType: "identify",
  userId: window.mtam.sso.userId,
  firstname: window.mtam.sso.firstname,
  lastname: window.mtam.sso.lastname,
  relationship: "friend",
  harness: window.mtam.sso.harness
});
```

The CDP agent sends `analytics.identify(userId, { firstname, lastname, relationship, harness })`. `userId` must be truthy. The four listed traits are read from the top level; other fields are not forwarded. An exact repeat of the last identified `userId` and traits is suppressed.

This example sets `relationship` explicitly to demonstrate a changed trait. A manual dataLayer push tests the event path only: it does not update `window.mtam.sso` or save a Preferences change.

### Page

```js
window.dataLayer.push({
  event: "homepagePage",
  eventType: "page",
  pageName: document.title,
  pagePath: window.location.pathname,
  pageUrl: window.location.href
});
```

The CDP agent sends `analytics.page(pageName || pagePath, { path: pagePath, url: pageUrl, title: pageName })`. `pagePath` is the pathname; `pageUrl` is the full URL, including any query string or fragment. If `pageName` is empty or absent, `pagePath` is used as the page name.

### Track

Hosted Apps report events through the Homepage bridge. Homepage validates the source iframe, origin, App slug, and exact instance before adding this dataLayer record; Apps do not call the CDP SDK directly.

```js
window.dataLayer.push({
  event: "homepageAppTrack",
  eventType: "track",
  trackEventName: "Generated Image",
  appSlug: "image-generator",
  properties: {}
});
```

`appSlug` is assigned by Homepage and forwarded as a trusted track property; Apps cannot override it. Event names are limited to 100 characters and `properties` must be a JSON object no larger than 16 KiB when serialized. The active agent sends `trackEventName` with `properties` after the initial profile `identify()`; tracks are queued while its SDK loads.

Homepage-owned tracks use `trackSource: "homepage"` and omit `appSlug`. For example, the Preferences-use event has this shape:

```js
window.dataLayer.push({
  event: "homepagePreferencesUsed",
  eventType: "track",
  trackSource: "homepage",
  trackEventName: "Use Preferences",
  properties: {}
});
```

Homepage starts measuring only when the user opens Preferences by clicking the Homepage logo. It emits this event once during that opening after at least 3 seconds of foreground-visible time and a deliberate interaction with a control in the drawer. URL-driven and other programmatic openings do not qualify. Preference values are not included in `properties`.

Keep event properties safe for CDP delivery. Do not include credentials, secrets, generated image bytes, private prompts, or other sensitive request data.
