npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@newrelic/video-caf

v4.0.0

Published

New Relic tracker for CAF Receivers

Downloads

249

Readme

Community Project header

New Relic CAF Tracker

npm version License

The New Relic CAF Tracker provides comprehensive video analytics for Chromecast receiver applications built with the Cast Application Framework (CAF). Track playback events, monitor quality, identify errors, and gain deep insights into streaming performance and user experience on Chromecast devices.

Features

  • Automatic Event Detection - Captures CAF PlayerManager events automatically without manual instrumentation
  • Ad Break Tracking - Full support for CAF ad breaks including quartile progress events
  • Sender User Agent - Automatically captures the sender device user agent
  • Quality Monitoring - Bitrate and rendition change tracking
  • Error Tracking - Detailed error codes with CAF-specific error classification
  • Easy Integration - NPM package or direct script include
  • QoE Metrics - Quality of Experience aggregation for startup time, buffering, and playback quality
  • Event Segregation - Organized event types: VideoAction, VideoAdAction, VideoErrorAction, VideoCustomAction

Table of Contents

Installation

Option 1: Install via NPM/Yarn

Install the package using your preferred package manager:

NPM:

npm install @newrelic/video-caf

Yarn:

yarn add @newrelic/video-caf

Option 2: Direct Script Include (Without NPM)

For quick integration without a build system, include the tracker directly in your receiver HTML:

<!DOCTYPE html>
<html>
  <head>
    <!-- New Relic CAF Tracker -->
    <script src="path/to/newrelic-caf.min.js"></script>

    <!-- CAF Receiver SDK -->
    <script src="//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"></script>
  </head>
  <body>
    <cast-media-player></cast-media-player>

    <script>
      const receiverContext = cast.framework.CastReceiverContext.getInstance();

      // Retrieve these credentials by following the Streaming Video & Ads onboarding steps in New Relic Browser (one.newrelic.com)
      const options = {
        info: {
          licenseKey:    'YOUR_LICENSE_KEY',
          beacon:        'YOUR_BEACON_URL',
          applicationID: 'YOUR_APPLICATION_ID',
        },
      };

      // Initialize tracker BEFORE calling receiverContext.start()
      const tracker = new CAFTracker(receiverContext, options);

      receiverContext.start();
    </script>
  </body>
</html>

Setup Steps:

  1. Get Configuration - Visit one.newrelic.com and follow the Streaming Video & Ads onboarding flow to get your licenseKey, beacon, and applicationID.
  2. Integrate - Include the script in your receiver and initialize with your configuration before calling receiverContext.start().

Prerequisites

Before using the tracker, ensure you have:

  • New Relic Account - Active New Relic account with valid credentials (beacon, applicationID, licenseKey)
  • CAF Receiver SDK - The Cast Application Framework Receiver SDK loaded in your receiver page
  • Chromecast Device or Emulator - A real Chromecast device or the Chromecast Device Emulator for local testing

Usage

Getting Your Configuration

Before initializing the tracker, obtain your New Relic configuration:

  1. Log in to one.newrelic.com
  2. Navigate to the video agent onboarding flow
  3. Copy your credentials: licenseKey, beacon, and applicationID

Basic Setup

import CAFTracker from '@newrelic/video-caf';

// 1. Get the CastReceiverContext singleton
const receiverContext = cast.framework.CastReceiverContext.getInstance();

// 2. Retrieve these credentials by following the Streaming Video & Ads onboarding steps in New Relic Browser (one.newrelic.com)
const options = {
  info: {
    licenseKey:    'YOUR_LICENSE_KEY',
    beacon:        'bam.nr-data.net',
    applicationID: 'YOUR_APPLICATION_ID',
  },
};

// 3. Initialize tracker BEFORE receiverContext.start()
const tracker = new CAFTracker(receiverContext, options);

// 4. Start the receiver
receiverContext.start();

Important: The tracker must be initialized before calling receiverContext.start() to ensure all playback events are captured from the beginning of the session.

Advanced Configuration

const options = {
  info: {
    licenseKey:    'YOUR_LICENSE_KEY',
    beacon:        'YOUR_BEACON_URL',
    applicationID: 'YOUR_APPLICATION_ID',
  },
  config: {
    qoeAggregate: true,        // Enable QoE event aggregation
    qoeIntervalFactor: 2,      // Send QoE events every 2 harvest cycles
  },
  customData: {
    contentTitle:     'My Video Title',
    customPlayerName: 'MyCustomPlayer',
    customAttribute:  'customValue',
  },
};

const tracker = new CAFTracker(receiverContext, options);

Best Practices

1. Setting contentTitle

The contentTitle attribute is populated from the media metadata title if present. For best results, explicitly set it via customData:

const tracker = new CAFTracker(receiverContext, {
  info: {
    licenseKey:    'YOUR_LICENSE_KEY',
    beacon:        'YOUR_BEACON_URL',
    applicationID: 'YOUR_APPLICATION_ID',
  },
  customData: {
    contentTitle: 'My Video Title',
  },
});

If your content changes dynamically (e.g., a playlist or queue):

tracker.sendOptions({
  customData: {
    contentTitle: 'New Video Title',
  },
});

2. Setting userId

Track analytics per user by setting a user identifier:

// Set userId during initialization
const tracker = new CAFTracker(receiverContext, {
  info: {
    licenseKey:    'YOUR_LICENSE_KEY',
    beacon:        'YOUR_BEACON_URL',
    applicationID: 'YOUR_APPLICATION_ID',
  },
  customData: {
    userId: 'user-12345',
  },
});

// Or set userId separately after initialization
tracker.setUserId('user-12345');

3. Adding Custom Attributes

Enrich your analytics data with deployment-specific attributes:

const tracker = new CAFTracker(receiverContext, {
  info: {
    licenseKey:    'YOUR_LICENSE_KEY',
    beacon:        'YOUR_BEACON_URL',
    applicationID: 'YOUR_APPLICATION_ID',
  },
  customData: {
    contentTitle:     videoMetadata.title,
    userId:           currentUser.id,
    subscriptionTier: 'premium',
    contentProvider:  'studio-abc',
    region:           'us-west-2',
    appVersion:       '2.1.0',
  },
});

Use these attributes in New Relic queries:

-- Analyze content starts by subscription tier
SELECT count(*) FROM VideoAction WHERE actionName = 'CONTENT_START'
FACET subscriptionTier SINCE 1 day ago

-- Monitor bitrate by region
SELECT average(contentBitrate) FROM VideoAction
FACET region SINCE 1 hour ago

4. Gradual Rollout with Feature Flags

When deploying to production, use feature flags to enable the tracker gradually. This helps you:

  • Validate data collection without impacting all users
  • Monitor performance impact at scale
  • Catch issues before full deployment
  • Control monitoring costs
// Example using a feature flag
const rolloutPercentage = 5; // Start with 5% of users

function shouldEnableTracking(userId) {
  // Simple percentage-based rollout
  const hash = userId.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
  return (hash % 100) < rolloutPercentage;
}

const receiverContext = cast.framework.CastReceiverContext.getInstance();

// Only initialize tracker if user is in rollout
if (shouldEnableTracking(currentUser.id)) {
  const tracker = new CAFTracker(receiverContext, {
    info: {
      licenseKey: 'YOUR_LICENSE_KEY',
      beacon: 'YOUR_BEACON_URL',
      applicationID: 'YOUR_APP_ID',
    },
    customData: {
      contentTitle: videoMetadata.title,
      userId: currentUser.id,
      rolloutGroup: `${rolloutPercentage}%`,  // Track which rollout group
    },
  });
}

receiverContext.start();

Recommended Rollout Schedule:

| Phase | Percentage | Duration | Validation | |-------|-----------|----------|------------| | Initial | 5% | 2-3 days | Verify data flowing to New Relic | | Early | 15% | 3-5 days | Check data quality and performance | | Expansion | 25% | 5-7 days | Validate across device types | | Majority | 50% | 1-2 weeks | Monitor at scale | | Full | 100% | Ongoing | Complete deployment |

Configuration Options

options.info (required)

| Field | Type | Description | |-------|------|-------------| | licenseKey | string | New Relic Browser license key | | beacon | string | Data endpoint — use bam.nr-data.net | | applicationID | string | New Relic application ID |

QoE (Quality of Experience) Settings

| Option | Type | Default | Description | |--------|------|---------|-------------| | qoeAggregate | boolean | false | Enable Quality of Experience event aggregation. Set to true to collect QoE metrics like startup time, buffering, and average bitrate. | | qoeIntervalFactor | number | 1 | Controls QoE event frequency. A value of N sends QoE events once every N harvest cycles. Must be a positive integer. QoE events are always included on first and final harvest cycles. |

Custom Data

Add custom attributes to all events:

customData: {
  contentTitle:        'My Video Title',   // Override video title
  customPlayerName:    'MyPlayer',         // Custom player identifier
  customPlayerVersion: '1.0.0',           // Custom player version
  userId:              '12345',            // User identifier
  // Any additional custom attributes
}

Limit: The maximum total number of custom attributes per event is 150. Any attributes beyond this limit will be dropped.

Note: There are special keywords reserved for default attributes (see DATAMODEL.md). Please do not use these as custom attributes, as they will be dropped. Examples of reserved keywords include actionName, contentId, contentTitle, playerName, playerVersion, viewSession, viewId, and others listed in the data model documentation.

API Reference

Core Methods

tracker.setUserId(userId)

Set a unique identifier for the current user.

tracker.setUserId('user-12345');

tracker.setHarvestInterval(milliseconds)

Configure how frequently data is sent to New Relic. Accepts values between 1000ms (1 second) and 300000ms (5 minutes).

tracker.setHarvestInterval(30000); // Send data every 30 seconds

tracker.sendCustom(actionName, state, attributes)

Send a custom event with arbitrary attributes.

tracker.sendCustom('CUSTOM_ACTION', 'state time', {
  test1: 'value1',
  test2: 'value2',
});

tracker.sendOptions(options)

Update custom data after initialization.

tracker.sendOptions({
  customData: {
    contentTitle: 'New Video Title',
  },
});

Example: Complete Integration

import CAFTracker from '@newrelic/video-caf';

const receiverContext = cast.framework.CastReceiverContext.getInstance();

const tracker = new CAFTracker(receiverContext, {
  info: {
    licenseKey:    'YOUR_LICENSE_KEY',
    beacon:        'YOUR_BEACON_URL',
    applicationID: 'YOUR_APPLICATION_ID',
  },
  config: {
    qoeAggregate: true,
  },
  customData: {
    contentTitle: 'My Video',
    userId:       'user-12345',
  },
});

// Configure reporting interval
tracker.setHarvestInterval(30000);

receiverContext.start();

Data Model

The tracker captures comprehensive video analytics across four event types:

  • VideoAction — Playback events (start, pause, buffer, seek, rendition changes, heartbeats)
  • VideoAdAction — Ad break events (ad start, quartile progress, completions)
  • VideoErrorAction — Error events (playback failures, ad errors, network errors)
  • VideoCustomAction — Custom events defined by your application

Full Documentation: See DATAMODEL.md for the complete event and attribute reference.

Known Limitations

  • When a video END event fires, the contentSrc attribute is incorrect. This is due to how the Chromecast player clears media information before the event is emitted.

Support

Should you need assistance with New Relic products, you are in good hands with several support channels.

If the issue has been confirmed as a bug or is a feature request, please file a GitHub issue.

Support Channels

Additional Resources

Contribute

We encourage your contributions to improve the New Relic CAF Tracker! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.

If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at [email protected].

For more details on how best to contribute, see CONTRIBUTING.md.

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through our bug bounty program.

If you would like to contribute to this project, review these guidelines.

To all contributors, we thank you! Without your contribution, this project would not be what it is today.

License

New Relic CAF Tracker is licensed under the Apache 2.0 License.

The New Relic CAF Tracker also uses source code from third-party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the third-party notices document.