> ## Documentation Index
> Fetch the complete documentation index at: https://playerzero.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Script Tag Setup Guide

> This guide walks you through setting up the PlayerZero SDK using a script tag to start monitoring and improving your frontend applications.

## Prerequisites

* Access to your project’s frontend codebase.
* Your PlayerZero [API Key](https://playerzero.ai/current-org/settings/projects/current-project/api-tokens).

## Step-by-Step Instructions

### 1. Add the PlayerZero Script

Paste this inside your `<head>` or just before the closing `</body>` tag. Replace `YOUR_WEBSDK_TOKEN` with your API key; the placeholder URL will not load if opened directly in a browser.

```javascript theme={null}
<script type="text/javascript"
        src="https://go.playerzero.app/record/YOUR_WEBSDK_TOKEN"
        async crossorigin>
</script>
```

### 2. Identify the User (Recommended)

Once the user is authenticated or known:

```javascript theme={null}
<script>
  playerzero.identify("user-id", {
    name: "Jane Doe",
    email: "jane@example.com",
    group: "Marketing",
  });
</script>
```

***

### Example Implementations

#### Single Page Application (SPA) Setup

Once PlayerZero has been initialized, the below snippet demonstrates how to call the playerzero.identify method and capture user details in PlayerZero.

```javascript theme={null}
const userId = "userId";
const metadata = {
  name: "<DISPLAY_NAME>",
  email: "<USER_EMAIL>",
  group: "<CUSTOMER_ID_OR_OTHER_GROUP>", // Optional
};

if (window.playerzero) {
  window.playerzero.identify(userId, metadata);
} else {
  window.addEventListener(
    "playerzero_ready",
    () => { window.playerzero.identify(userId, metadata) },
    { once: true }
  );
}
```

#### Server Side Rendered (SSR) Setup

Once PlayerZero has been initialized, the below snippet demonstrates how to call the playerzero.identify method and capture user details in PlayerZero.

```javascript theme={null}
const userId = "<USER_ID>";
const metadata = {
  name: "<USER_NAME>",
  email: "<USER_EMAIL>",
  group: "<CUSTOMER_ID_OR_OTHER_GROUP>", // optional
};

const setCookie = (traceId) => {
  document.cookie = `pz-traceid=${traceId}; Path=/;`;
};

if (window.playerzero) {
  // PlayerZero has loaded
  window.playerzero.identify(userId, metadata);
  window.playerzero.onTraceChange(setCookie);
} else {
  // Wait for PlayerZero to load
  window.addEventListener(
    "playerzero_ready",
    () => {
      window.playerzero.identify(userId, metadata);
      window.playerzero.onTraceChange(setCookie);
    },
    { once: true }
  );
}
```

## Next Steps

Once the SDK is installed and initialized, you can visit the [Users page](https://playerzero.ai/current-org/current-project/users) in PlayerZero to see live user sessions being captured.

If you want to control where PlayerZero is active, visit the [Domain Settings](/developer-guide/configuration-guides/capturing-user-sessions/domain-settings) guide to configure domain-level access and environment-specific behavior.

Want to extend your integration further? Explore the [Advanced SDK Usage](/developer-guide/configuration-guides/capturing-user-sessions/advanced-usage) guide to unlock features like custom event tracking, devtools links, and user metadata enhancements.
