Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ jobs:

youtubePackageJson.peerDependencies = {
...youtubePackageJson.peerDependencies,
'@analytics-sdk/core': `^${newVersion}`,
'tanilytics': `^${newVersion}`,
};

youtubePackageJson.devDependencies = {
...youtubePackageJson.devDependencies,
'@analytics-sdk/core': `^${newVersion}`,
'tanilytics': `^${newVersion}`,
};

fs.writeFileSync(
Expand All @@ -136,33 +136,33 @@ jobs:

# Update version.ts so the SDK reports its own version correctly
echo "// Updated automatically by the release pipeline — do not edit manually" > packages/core/src/version.ts
echo "export const SDK_VERSION = '$NEW';" >> packages/core/src/version.ts
echo "export const VERSION = '$NEW';" >> packages/core/src/version.ts

# ── Rebuild with new version ──────────────────────────────────────────────
# The version number is baked into the bundle at build time
- name: Rebuild with updated version
run: npx nx run-many --target=build --all

# ── Publish to npm ────────────────────────────────────────────────────────
- name: Publish @analytics-sdk/core
- name: Publish tanilytics
working-directory: packages/core
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# - name: Publish @analytics-sdk/adapter-videojs
# - name: Publish @tanilytics/adapter-videojs
# working-directory: packages/media-adapters/videojs
# run: npm publish --access public
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# - name: Publish @analytics-sdk/adapter-hlsjs
# - name: Publish @tanilytics/adapter-hlsjs
# working-directory: packages/media-adapters/hlsjs
# run: npm publish --access public
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish @analytics-sdk/adapter-youtube
- name: Publish @tanilytics/adapter-youtube
working-directory: packages/media-adapters/youtube
run: npm publish --access public
env:
Expand Down
26 changes: 13 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ For public API changes, review `packages/core/src/index.ts` and package `exports

This repo uses npm workspaces with Nx.

- `packages/core/`: `@analytics-sdk/core`, the main browser analytics SDK
- `packages/media-adapters/videojs/`: `@analytics-sdk/adapter-videojs`
- `packages/media-adapters/hlsjs/`: `@analytics-sdk/adapter-hlsjs`
- `packages/media-adapters/youtube/`: `@analytics-sdk/adapter-youtube`
- `packages/core/`: `tanilytics`, the main browser analytics SDK
- `packages/media-adapters/videojs/`: `@tanilytics/adapter-videojs`
- `packages/media-adapters/hlsjs/`: `@tanilytics/adapter-hlsjs`
- `packages/media-adapters/youtube/`: `@tanilytics/adapter-youtube`
- `nx.json`: Nx target and plugin configuration
- `tsconfig.json` and `tsconfig.base.json`: workspace TypeScript settings
- `eslint.config.mjs`: shared flat ESLint config
Expand All @@ -92,18 +92,18 @@ Main workspace commands:

Common per-project commands:

- build core: `bunx nx build @analytics-sdk/core`
- test core: `bunx nx test @analytics-sdk/core`
- lint core: `bunx nx lint @analytics-sdk/core`
- typecheck core: `bunx nx typecheck @analytics-sdk/core`
- build adapter: `bunx nx build @analytics-sdk/adapter-videojs`
- test adapter: `bunx nx test @analytics-sdk/adapter-videojs`
- build core: `bunx nx build tanilytics`
- test core: `bunx nx test tanilytics`
- lint core: `bunx nx lint tanilytics`
- typecheck core: `bunx nx typecheck tanilytics`
- build adapter: `bunx nx build @tanilytics/adapter-videojs`
- test adapter: `bunx nx test @tanilytics/adapter-videojs`

Single-test commands:

- one core test file: `bunx nx test @analytics-sdk/core -- --run src/config/validator.test.ts`
- one named core test: `bunx nx test @analytics-sdk/core -- --run src/config/validator.test.ts -t "throws when siteToken is missing"`
- one adapter test file: `bunx nx test @analytics-sdk/adapter-videojs -- --run src/lib/videojs.spec.ts`
- one core test file: `bunx nx test tanilytics -- --run src/config/validator.test.ts`
- one named core test: `bunx nx test tanilytics -- --run src/config/validator.test.ts -t "throws when siteToken is missing"`
- one adapter test file: `bunx nx test @tanilytics/adapter-videojs -- --run src/lib/videojs.spec.ts`

Implementation details:

Expand Down
92 changes: 46 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Tanilytics Analytics SDK is a TypeScript monorepo for a browser analytics client

## Packages

- `@analytics-sdk/core`: browser analytics SDK
- `@analytics-sdk/adapter-videojs`: Video.js adapter package scaffold
- `@analytics-sdk/adapter-hlsjs`: hls.js adapter package scaffold
- `@analytics-sdk/adapter-youtube`: YouTube iframe adapter for the core SDK
- `tanilytics`: browser analytics SDK
- `@tanilytics/adapter-videojs`: Video.js adapter package scaffold
- `@tanilytics/adapter-hlsjs`: hls.js adapter package scaffold
- `@tanilytics/adapter-youtube`: YouTube iframe adapter for the core SDK

Today, the core package contains the main SDK implementation. The YouTube adapter is usable as a core extension, while the other media adapter packages are still minimal scaffolds.

Expand All @@ -27,7 +27,7 @@ Today, the core package contains the main SDK implementation. The YouTube adapte
Package consumers install from npm:

```bash
npm install @analytics-sdk/core
npm install tanilytics
```

For local repository development:
Expand All @@ -39,55 +39,55 @@ bun install
## Quick Start

```ts
import analytics from '@analytics-sdk/core';
import tanilytics from 'tanilytics';

analytics.init({
tanilytics.init({
siteToken: 'sk_live_abc12345',
endpoint: 'https://ingest.example.com/api/v1/events',
});

analytics.track('audio_downloaded', {
tanilytics.track('audio_downloaded', {
audioId: 'aud_123',
format: 'mp3',
source: 'player',
});

analytics.track('signup_clicked', {
tanilytics.track('signup_clicked', {
plan: 'pro',
});
```

You can also provide the ingestion endpoint through the `INGESTION_URL` environment variable instead of passing `endpoint` to `analytics.init()`.
You can also provide the ingestion endpoint through the `INGESTION_URL` environment variable instead of passing `endpoint` to `tanilytics.init()`.

## Public API

The current public API for `@analytics-sdk/core` is a default export object with:
The current public API for `tanilytics` is a default export object with:

- `analytics.init(config)`
- `analytics.track(eventName, properties?)`
- `analytics.flush()`
- `analytics.destroy()`
- `analytics.optOut()`
- `analytics.optIn()`
- `analytics.isOptedOut()`
- `analytics.giveConsent()`
- `analytics.withdrawConsent()`
- `analytics.EventTypes`
- `analytics.SDK_VERSION`
- `tanilytics.init(config)`
- `tanilytics.track(eventName, properties?)`
- `tanilytics.flush()`
- `tanilytics.destroy()`
- `tanilytics.optOut()`
- `tanilytics.optIn()`
- `tanilytics.isOptedOut()`
- `tanilytics.giveConsent()`
- `tanilytics.withdrawConsent()`
- `tanilytics.EventTypes`
- `tanilytics.VERSION`

The package also exports types including `AnalyticsConfig`, `EventType`, `EventProperties`, and `IngestionEvent`.
The package also exports types including `TanilyticsConfig`, `EventType`, `EventProperties`, and `IngestionEvent`.

`AnalyticsConfig` also supports `adapters?: readonly MediaAdapterInterface[]` for media extensions.
`TanilyticsConfig` also supports `adapters?: readonly MediaAdapterInterface[]` for media extensions.

## Media Adapters

Adapters are registered through `analytics.init()` and emit the core media event types through the same privacy, session, and queue pipeline.
Adapters are registered through `tanilytics.init()` and emit the core media event types through the same privacy, session, and queue pipeline.

```ts
import analytics from '@analytics-sdk/core';
import { youtubeAdapter } from '@analytics-sdk/adapter-youtube';
import tanilytics from 'tanilytics';
import { youtubeAdapter } from '@tanilytics/adapter-youtube';

analytics.init({
tanilytics.init({
siteToken: 'sk_live_abc12345',
endpoint: 'https://ingest.example.com/api/v1/events',
adapters: [youtubeAdapter()],
Expand All @@ -101,7 +101,7 @@ analytics.init({
Manual tracking accepts any custom event name:

```ts
analytics.track('audio_downloaded', {
tanilytics.track('audio_downloaded', {
audioId: 'aud_123',
format: 'mp3',
});
Expand All @@ -126,10 +126,10 @@ The SDK also emits fixed internal event types for autocapture and media adapters

## Configuration

`analytics.init()` accepts this shape:
`tanilytics.init()` accepts this shape:

```ts
interface AnalyticsConfig {
interface TanilyticsConfig {
siteToken: string;
endpoint?: string;
flushInterval?: number;
Expand Down Expand Up @@ -166,13 +166,13 @@ Current defaults:
Autocapture can be configured in two ways:

```ts
analytics.init({
tanilytics.init({
siteToken: 'sk_live_abc12345',
endpoint: 'https://ingest.example.com/api/v1/events',
autocapture: true,
});

analytics.init({
tanilytics.init({
siteToken: 'sk_live_abc12345',
endpoint: 'https://ingest.example.com/api/v1/events',
autocapture: {
Expand Down Expand Up @@ -205,14 +205,14 @@ Validation rules currently enforced by the SDK include:
The SDK exposes helpers for common privacy flows:

```ts
import analytics from '@analytics-sdk/core';
import tanilytics from 'tanilytics';

analytics.optOut();
analytics.optIn();
analytics.giveConsent();
analytics.withdrawConsent();
tanilytics.optOut();
tanilytics.optIn();
tanilytics.giveConsent();
tanilytics.withdrawConsent();

console.log(analytics.isOptedOut());
console.log(tanilytics.isOptedOut());
```

Current privacy behavior:
Expand Down Expand Up @@ -251,19 +251,19 @@ Useful per-project commands:

```bash
# core
bunx nx build @analytics-sdk/core
bunx nx test @analytics-sdk/core
bunx nx lint @analytics-sdk/core
bunx nx typecheck @analytics-sdk/core
bunx nx build tanilytics
bunx nx test tanilytics
bunx nx lint tanilytics
bunx nx typecheck tanilytics

# single core test file
bunx nx test @analytics-sdk/core -- --run src/config/validator.test.ts
bunx nx test tanilytics -- --run src/config/validator.test.ts

# single named core test
bunx nx test @analytics-sdk/core -- --run src/config/validator.test.ts -t "throws when siteToken is missing"
bunx nx test tanilytics -- --run src/config/validator.test.ts -t "throws when siteToken is missing"

# adapter example
bunx nx test @analytics-sdk/adapter-videojs -- --run src/lib/videojs.spec.ts
bunx nx test @tanilytics/adapter-videojs -- --run src/lib/videojs.spec.ts
```

## Repository Structure
Expand Down
Loading
Loading