diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 1320b9a..0000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["@babel/preset-env"] -} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a77f6e5..928198c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,10 +22,13 @@ jobs: with: ref: 'refs/heads/master' + - name: Setup pnpm + uses: pnpm/action-setup@v4 + - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 registry-url: 'https://registry.npmjs.org' - name: Configure Git @@ -33,18 +36,15 @@ jobs: git config user.name "cloudinary-bot" git config user.email "cloudinary-bot@clodinary.com" - - name: Setup yarn - run: npm install -g yarn - - name: Install dependencies - run: yarn install --frozen-lockfile + run: pnpm install - name: Bump version run: npm version ${{ github.event.inputs.version-type }} -m "Bumping to version %s" --tag-version-prefix="" - name: Build shell: bash - run: yarn build + run: pnpm build - name: Publish packages run: npm publish --access="public" diff --git a/.gitignore b/.gitignore index 3f6f8f5..96aab62 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ tags # nodejs node_modules/ npm-debug.log -yarn-error.log +pnpm-debug.log # project env.js diff --git a/.npmignore b/.npmignore index e11cf97..d4bec2d 100644 --- a/.npmignore +++ b/.npmignore @@ -6,7 +6,7 @@ tags # nodejs node_modules/ npm-debug.log -yarn-error.log +pnpm-debug.log # project env.js diff --git a/README.md b/README.md index 83279d8..b8f552a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # Cloudinary Video Analytics The Cloudinary Video Analytics package allows you to track analytics for your Cloudinary videos using video players other than the Cloudinary Video Player. The library targets the HTML5 video tag and is designed to work with any video player that use this tag. For more information view the [documentation](https://cloudinary.com/documentation/video_analytics). -### Usage +The package is written in TypeScript and ships its own type declarations. + +## Usage **1. Install the package**: ```shell @@ -12,7 +14,7 @@ npm i cloudinary-video-analytics ```js import { connectCloudinaryAnalytics } from 'cloudinary-video-analytics'; ``` -**3. Connect the analytics:**: +**3. Connect the analytics**: Connect the analytics by calling the `connectCloudinaryAnalytics` method and provide the video element as a parameter. For example, if your video element has the id ‘video-player’: ```js @@ -36,7 +38,140 @@ cloudinaryAnalytics.startManualTracking({ Auto and manual tracking cannot be used together for the same video element. Manual tracking should only be used in cases where you need to track certain videos, you want to track a video tag element which is dynamic, or you have custom domains which require providing `cloudName` and `publicId`. -### CodeSandbox examples +## API + +`connectCloudinaryAnalytics(videoElement, mainOptions?)` returns an object with the following methods: + +| Method | Description | +| --- | --- | +| `startAutoTracking(options?)` | Automatically detects and tracks Cloudinary videos played in the element. | +| `startManualTracking(metadata, options?)` | Tracks a specific video (or live stream) identified by `cloudName` / `publicId`. | +| `stopManualTracking()` | Stops the current tracking session. | +| `stopAutoTracking()` | Alias of `stopManualTracking` — stops the current tracking session. | +| `stopTracking()` | Stops whichever tracking (auto or manual) is currently active. | +| `reportCustomEvent(name, data?)` | Records a consumer-defined event into the current view (see [Custom events](#custom-events)). | + +### `metadata` (manual tracking) + +| Field | Type | Description | +| --- | --- | --- | +| `cloudName` | `string` | Your Cloudinary cloud name. Required. | +| `publicId` | `string` | Public ID of the video (or live stream output). Required. | +| `type` | `'live'` | Optional. Set to `'live'` to track a live stream. | + +### `options` (tracking options) + +| Field | Type | Description | +| --- | --- | --- | +| `customData` | `object \| () => object` | Up to five string fields (`customData1`…`customData5`); non-string values are ignored. | +| `videoPlayerType` | `string` | `'native'` (default) or `'cloudinary video player'`. | +| `videoPlayerVersion` | `string` | Semantic version of the player. | +| `customVideoUrlFallback` | `(videoUrl) => ({ cloudName, publicId })` | Resolves `cloudName`/`publicId` from a video URL (auto tracking / custom domains). | + +### `mainOptions` + +| Field | Type | Description | +| --- | --- | --- | +| `playerAdapter` | `PlayerAdapter` | Custom player adapter. Defaults to the built-in native HTML5 `