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

@truex/ad-renderer-vega

v0.8.3

Published

TrueX Ad Renderer for Vega OS

Readme

TruexAdRenderer-Vega

TrueX Ad Renderer for Amazon Vega OS (Kepler) - A React Native library for integrating interactive TrueX ads into your Vega-based applications.

Installation

Install the package via npm:

npm install --save @truex/ad-renderer-vega

Peer Dependencies

This library requires the following peer dependencies to be installed in your project:

npm install \
  @amazon-devices/react-native-device-info@~2.0.0 \
  @amazon-devices/webview@~3.3.0

Usage

Import the Component

import { TruexAd, TruexAdEventType, TruexAdOptions } from '@truex/ad-renderer-vega';

Create an Instance

The TruexAd component can be instantiated in your React Native application by providing the required props:

import React, { useCallback, useMemo, useState } from 'react';
import { View } from 'react-native';
import { TruexAd, TruexAdEventType, TruexAdRendererOptions, TruexAdEventHandler } from '@truex/ad-renderer-vega';

function MyVideoPlayer({ adParameters }) {
  const [ showTruexAd, setShowTruexAd ] = useState(false);
  const [ hasAdCredit, setHasAdCredit ] = useState(false);

  // Configure TrueX ad options
  const tarOptions = useMemo<TruexAdRendererOptions>(() => ({
    supportsUserCancelStream: false, // Optional: enable user cancel stream events
    enableWebViewDebugging: false, // Optional: enable WebView debugging
  }), []);

  // Handle ad events
  const onAdEvent = useCallback<TruexAdEventHandler>((event) => {
    console.log(`TrueX event: ${event.type}`);

    switch (event.type) {
      case TruexAdEventType.AD_STARTED:
        // Ad UI is being constructed
        break;

      case TruexAdEventType.AD_DISPLAYED:
        // Ad UI is fully loaded and visible
        break;

      case TruexAdEventType.AD_FREE_POD:
        // User earned credit - skip remaining ads in this slot
        setHasAdCredit(true);
        break;

      case TruexAdEventType.AD_COMPLETED:
        // Ad finished - resume video playback
        setShowTruexAd(false);
        resumeVideoPlayback();
        break;

      case TruexAdEventType.AD_ERROR:
        // Error occurred - resume video playback
        console.error('TrueX ad error:', event.errorMessage);
        setShowTruexAd(false);
        resumeVideoPlayback();
        break;

      case TruexAdEventType.NO_ADS_AVAILABLE:
        // No ads to show - resume video playback
        setShowTruexAd(false);
        resumeVideoPlayback();
        break;
    }
  }, []);

  const resumeVideoPlayback = () => {
    // Resume your video player
  };

  return (
    <View>
      {/* Your video player UI */}

      {showTruexAd && (
        <TruexAd
          adParameters={adParameters}
          options={tarOptions}
          onAdEvent={onAdEvent}
        />
      )}
    </View>
  );
}

Listen to Events

The onAdEvent callback receives event objects with different types. Here are the key events to handle:

Terminal Events

These events indicate the ad experience is complete and you should resume playback:

  • adCompleted - User finished interacting with the ad
  • adError - An error occurred (includes errorMessage property)
  • noAdsAvailable - No ads available for this user
  • userCancelStream - User wants to exit the stream (requires supportsUserCancelStream: true)

Informational Events

  • adStarted - Ad UI construction has begun
  • adDisplayed - Ad UI is fully loaded and visible
  • adFetchCompleted - Ad request completed successfully, ready to present
  • adFreePod - User earned credit to skip ads
  • optIn - User chose to engage with interactive ad
  • optOut - User chose normal video ad experience
  • userCancel - User backed out of interactive ad
  • skipCardShown - Skip card is shown
  • popupWebsite - User clicked external link (includes url property)

Event Handler Type Safety

The library exports TypeScript types for full type safety:

import {
  TruexAdEventType,
  TruexAdEventHandler,
  isTerminalEvent
} from '@truex/ad-renderer-vega';

const onAdEvent: TruexAdEventHandler = (event) => {
  // event.type is properly typed
  if (isTerminalEvent(event)) {
    // Handle terminal events
  }

  // Access event-specific properties with type safety
  if (event.type === TruexAdEventType.AD_ERROR) {
    console.error(event.errorMessage);
  }

  if (event.type === TruexAdEventType.OPT_IN) {
    console.log('User initiated:', event.userInitiated);
  }
};

API Reference

TruexAd Component Props

type TruexAdProps = {
  adParameters?: TruexAdParameters,  // `<AdParameters/>` json object from VAST response
  options?: TruexAdRendererOptions,  // TruexAdRenderer configuration options
  onAdEvent: TruexAdEventHandler,    // Event callback (required)
};

TruexAdRendererOptions

type TruexAdRendererOptions = {
  supportsUserCancelStream?: boolean,  // Enable user cancel stream events
  userAdvertisingId?: string,          // User ID for analytics
  appId?: string,                      // Application identifier
  enableWebViewDebugging?: boolean,    // Enable WebView debugging
};

Best Practices

  1. Always handle terminal events: Ensure you handle adCompleted, adError, noAdsAvailable, and optionally userCancelStream to properly resume playback.

  2. Track ad credits: When adFreePod fires, remember to skip remaining ads in the current ad slot.

  3. Hide controls during ad: Prevent user interaction with your video player controls while the TrueX ad is showing.

Example Integration Flow

// 1. Detect ad break in your video
const onAdBreak = () => {
  pauseVideoPlayer();
  setShowTruexAd(true);
};

// 2. Show TruexAd component
<TruexAd
  adParameters={adParameters}
  options={tarOptions}
  onAdEvent={onAdEvent}
/>

// 3. Handle terminal ad events (completion, errors, no-ads)
const onAdEvent = (event) => {
  if (isTerminalEvent(event)) {
    setShowTruexAd(false);

    if (hasAdCredit) {
      // Skip to end of ad break
      seekToEndOfAdBreak();
    } else {
      // Resume normal playback
      resumeVideoPlayer();
    }
  }
};

Version Information

Access the library version at runtime:

import { version, buildInfo } from '@truex/ad-renderer-vega';

console.log('TruexAd Version:', version);
console.log('Build Info:', buildInfo);

License

MIT