# @stadionhq/dynamic-yield-js

> Dynamic Yield API client for JavaScript

Latest version **0.0.27** (published 2025-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @stadionhq/dynamic-yield-js
pnpm add @stadionhq/dynamic-yield-js
yarn add @stadionhq/dynamic-yield-js
bun add @stadionhq/dynamic-yield-js
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.27 |
| Published | 2025-08-22 |
| First published | 2025-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | StadionHQ |
| Maintainers | stadion-dev, anthlasserre, ludwig-pro, dluksza |
| Keywords | dynamic-yield, dynamic-yield-js, dynamic-yield-api, dynamic-yield-client, dynamic |

## Links

- npm: https://www.npmjs.com/package/@stadionhq/dynamic-yield-js
- Repository: https://github.com/stadionhq/dynamic-yield-js
- Homepage: https://github.com/stadionhq/dynamic-yield-js#readme
- Issues: https://github.com/stadionhq/dynamic-yield-js/issues
- npm.io page: https://npm.io/package/@stadionhq/dynamic-yield-js

## Dependencies (2)

- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.2
- [openapi-fetch](https://npm.io/package/openapi-fetch.md) ^0.14.0

## Recent versions

- 0.0.27 (latest) — 2025-08-22
- 0.0.26 — 2025-08-20
- 0.0.25 — 2025-07-29
- 0.0.24 — 2025-07-29
- 0.0.23 — 2025-06-25
- 0.0.22 — 2025-06-16
- 0.0.21 — 2025-06-12
- 0.0.20 — 2025-05-27
- 0.0.19 — 2025-05-27
- 0.0.18 — 2025-05-27
- 0.0.17 — 2025-05-27
- 0.0.16 — 2025-05-27
- 0.0.15 — 2025-05-27
- 0.0.14 — 2025-05-27
- 0.0.13 — 2025-05-27
- … 13 more at https://npm.io/package/@stadionhq/dynamic-yield-js/versions

## README

# Dynamic Yield JavaScript Client

A TypeScript/JavaScript client for the Dynamic Yield API, providing a simple and type-safe way to interact with Dynamic Yield's services.

## Installation

```bash
# Using npm
npm install @stadionhq/dynamic-yield-js

# Using yarn
yarn add @stadionhq/dynamic-yield-js

# Using bun
bun add @stadionhq/dynamic-yield-js
```

## Usage

```typescript
import { DynamicYieldClient } from '@stadionhq/dynamic-yield-js';

// Initialize the client
const client = new DynamicYieldClient({
  apiKey: 'your-api-key',
  dataCenter: 'us', // or 'eu', defaults to 'us'
  version: 'v2', // optional, defaults to 'v2'
  extraHeaders: {} // optional additional headers
});

// Example: Choose variations
const variations = await client.chooseVariations({
  user: { id: 'user123' },
  context: { page: 'home' },
  options: {
    variations: [{ id: 'variation1' }]
  }
});

// Example: Track pageview
await client.trackPageviews({
  user: { id: 'user123' },
  context: { page: 'product' }
});
```

## Available Methods

The client provides methods for all Dynamic Yield API endpoints:

- `chooseVariations()` - Choose variations for a user
- `trackPageviews()` - Track page views
- `trackEngagement()` - Track user engagement
- `search()` - Perform search operations
- `trackEvents()` - Track custom events
- `updateProductFeed()` - Update product feed
- `trackTransactionStatusSpecificItem()` - Track transaction status for specific items
- `trackTransactionStatusWholeTransaction()` - Track transaction status for whole transactions
- `updateBranchFeed()` - Update branch feed
- `reportOutages()` - Report outages
- `userDataApi()` - User data operations
- `externalEventsApi()` - Track external events
- `profileAnywhere()` - Access user profile data
- `setActiveConsentAccepted()` - Set user consent status

## Configuration

The client accepts the following configuration options:

```typescript
interface DYApiConfig {
  apiKey: string;           // Your Dynamic Yield API key
  dataCenter?: 'us' | 'eu'; // Data center to use (defaults to 'us')
  version?: string;         // API version (defaults to 'v2')
  extraHeaders?: Record<string, string>; // Additional headers to include
}
```

## Error Handling

All API calls will throw an error if the request fails. The error message will include the HTTP status code:

```typescript
try {
  await client.chooseVariations({/*...*/});
} catch (error) {
  console.error('API call failed:', error.message);
}
```

## Development

```bash
# Install dependencies
yarn install

# Run tests
yarn test

# Run tests in watch mode
yarn test:watch

# Build the project
yarn build
```

## License

MIT

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Repository

[GitHub Repository](https://github.com/stadionhq/dynamic-yield-js)

---
_Source: https://npm.io/package/@stadionhq/dynamic-yield-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
