# Record page views on your website — Segment

> The page method lets you record page views on your website, along with optional extra information about the page being viewed (note requires userId or anonymousId). See the docs here

- Key: `segment-page`
- Type: Action (Write)
- Version: 0.2.6
- App: Segment (`segment`) — https://pipedream.com/apps/segment.md
- This page (HTML): https://pipedream.com/apps/segment/actions/page
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/segment/actions/page/page.mjs

## Description

The page method lets you record page views on your website, along with optional extra information about the page being viewed (note requires userId or anonymousId). See the docs [here](https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#page)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `anonymousId` | `string` | No | A pseudo-unique substitute for a User ID, for cases when you don't have an absolutely unique identifier. A User ID or an Anonymous ID is required. |
| `context` | `object` | No | Dictionary of extra information that provides useful context about a message, but is not directly related to the API call like ip address or locale |
| `integrations` | `object` | No | Dictionary of destinations to either enable or disable |
| `label` | `string` | No | Name of the page |
| `properties` | `object` | No | Free-form dictionary of properties of the page, like url and referrer |
| `timestamp` | `string` | No | Timestamp when the message itself took place, defaulted to the current time by the Segment Tracking API. It is an ISO-8601 date string. For example, 2022-04-08T17:32:11.318Z |
| `userId` | `string` | No | Unique identifier for the user in your database., A User ID or an Anonymous ID is required. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "segment",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "segment-page",
  arguments: {
    anonymousId: "Anonymous ID",
    context: "Context",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "segment-page",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    segment: { authProvisionId: "apn_xxxxxxx" },
    anonymousId: "Anonymous ID",
    context: "Context",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "segment-page",
    "configured_props": {
      "segment": { "authProvisionId": "apn_xxxxxxx" },
      "anonymousId": "Anonymous ID",
      "context": "Context"
    }
  }'
```

---

- App: https://pipedream.com/apps/segment.md · All apps: https://pipedream.com/apps
