Introduction
Server-Side Ad Insertion (SSAI) in NextGen Live API allows you to dynamically insert ads into your live streams. Macro variables are placeholders that get replaced with actual values at runtime, enabling precise ad targeting and tracking.
Macro variables can be used in:
- Ad server URLs - for sending contextual information to your ad server
- Custom beacon URLs - for tracking ad playback and engagement
This guide covers all supported macro variables, how to use them, and provides complete working examples.
Overview
NextGen Live supports all macro variables from Live 1.0, plus additional tracking and SCTE-35 macros. The workflow remains the same:
- Create an SSAI ad configuration with macro placeholders in the ad server URL
- Create a live job with SSAI enabled
- Insert cuepoints via the API or use SCTE-35 markers
- Macros are automatically replaced with actual values when ads are requested
Macro Syntax
Macros use double curly brace syntax:
{{macro.name}}
Example in an ad server URL:
https://ads.example.com/ad?session={{session.session_id}}&ip={{client.ipaddress}}&dur={{live.adbreakdurationms}}
Supported Macro Variables
Session & Job Macros
These macros provide information about the current streaming session and job.
| Macro | Description | Example Value |
|---|---|---|
{{session.session_id}} |
Unique session identifier | e039fd39-09f0-46b2-aca9-9871cc116cde |
{{job.job_id}} |
Unique job identifier | 6375714503112 |
{{videocloud.video_id}} |
Video ID (uses job_id) | 6375714503112 |
{{application_ad_configuration.description}} |
Ad config description | My Ad Config |
Random Value Macros
These macros generate random values, useful for cache-busting and unique identifiers. Random values are generated fresh for each ad request.
| Macro | Description | Example Value |
|---|---|---|
{{random.int32}} |
Random 32-bit signed integer | 1234567890 |
{{random.int64}} |
Random 64-bit signed integer | 1234567890123456789 |
{{random.uint32}} |
Random 32-bit unsigned integer | 2345678901 |
{{random.uint64}} |
Random 64-bit unsigned integer | 12345678901234567890 |
{{random.uuid}} |
Random UUID | 550e8400-e29b-41d4-a716-446655440000 |
Server & Timestamp Macros
These macros provide timing information for the ad break and request.
| Macro | Description | Example Value |
|---|---|---|
{{server.timestamputc}} |
Current time in milliseconds (epoch) | 1640995200000 |
{{live.adbreak.timestamputc.wallclock}} |
Current time in milliseconds (epoch) | 1640995200000 |
{{live.adbreak.timestamputc.origin}} |
Current time in milliseconds (epoch) | 1640995200000 |
{{live.adbreak.timestamputc.session}} |
Current time in milliseconds (epoch) | 1640995200000 |
Client Context Macros
These macros provide information about the viewer's context. All client context values are automatically URL-encoded.
| Macro | Description | URL Encoded | Example Value |
|---|---|---|---|
{{client.ipaddress}} |
Client IP (X-Forwarded-For) | Yes | 192.168.1.1 |
{{client.useragent}} |
User agent string | Yes | Mozilla%2F5.0... |
{{client.referrer}} |
HTTP referer (correct spelling) | Yes | https%3A%2F%2Fexample.com |
{{client.referer}} |
HTTP referer (HTTP spelling) | Yes | https%3A%2F%2Fexample.com |
{{client.ipuaid}} |
SHA256 hash of IP + user agent | No | a1b2c3d4e5... |
Ad Break Duration Macros
These macros provide the duration of the ad break in various formats.
| Macro | Description | Example Value |
|---|---|---|
{{live.adbreakdurationms}} |
Duration in milliseconds | 30000 |
{{live.adbreakduration}} |
Duration in floating-point seconds | 30.0 |
{{live.adbreakdurationint}} |
Duration in integer seconds | 30 |
{{live.adbreak}} |
Currently unused | UNSUPPORTED |
SCTE-35 Macros (RTP/SRT Inputs Only)
These macros are populated from SCTE-35 markers in the live stream. They are only available with RTP and SRT input protocols, not with RTMP.
| Macro | Description | Example Value |
|---|---|---|
{{scte.event_id}} |
Unique SCTE-35 event ID | 12345 |
{{scte.avail_num}} |
Avail number from SCTE-35 | 1 |
{{scte.avails_expected}} |
Expected count of avails | 3 |
{{scte.archive_allowed_flag}} |
Archive restrictions (0=restricted, 1=allowed) | 1 |
{{scte.delivery_not_restricted_flag}} |
Delivery restrictions | 1 |
{{scte.device_restrictions}} |
Device restriction groups (integer) | 0 |
Tracking Macros
These macros are useful for advanced tracking and analytics.
| Macro | Description | Example Value |
|---|---|---|
{{tracking.job_id}} |
Job ID for tracking | 6375714503112 |
{{tracking.ad_config_id}} |
Ad config ID | config-123 |
{{tracking.summary_id}} |
Summary ID for billing | uuid-123 |
{{tracking.debug_id}} |
Debug identifier | debug-456 |
{{tracking.ad_id}} |
Individual ad ID | ad-abc |
{{tracking.adbreak_id}} |
Ad break identifier | scte_12345_1 |
{{tracking.ad_provider_url}} |
Original ad server URL | https://ads.com/... |
{{tracking.event}} |
Tracking event type | start |
{{tracking.jwt}} |
JWT token for stateless tracking | eyJhbGciOi... |
Custom URL Macros
NextGen Live SSAI supports custom ad targeting parameters via the {{url.*}} macro pattern. Any parameter passed by the client during session initialization is available as {{url.<key>}} in the ad tag URL.
| Macro | Description | URL Encoded | Example Value |
|---|---|---|---|
{{url.key}} |
Custom parameter passed by the client during session initialization. Replace key with any parameter name (e.g., csid, prof, uid) |
Yes | Depends on value sent by client |
{{url.givn}} |
Google PAL nonce — automatically injected by the Brightcove Player SSAI plugin when PAL is enabled | Yes | AQzzBGQEAwo... (PAL nonce) |
{{givn}} |
Alias for url.givn |
Yes | AQzzBGQEAwo... (PAL nonce) |
How to Use
1. In your ad configuration, reference custom parameters using the {{url.*}} syntax:
{
"ad_server": {
"url": "https://ads.example.com/ad?csid={{url.csid}}&prof={{url.prof}}&cb={{random.uint32}}&session={{session.session_id}}"
}
}
2. From the client, pass matching parameter values. There are two ways to do this:
Option A: Via the Brightcove Player or Native SDKs
The Brightcove Player and Native SDKs send custom parameters as adsParams in the session initialization POST request. For implementation details, see Ad Targeting with Custom Parameters.
Option B: Via query parameters on the playback URL
You can also pass custom parameters directly as query parameters on the playback URL, using the ads. prefix. For example, to pass csid and prof:
https://ssai.live.brightcove.com/.../playlist-hls.m3u8?ads.csid=mysite-section&ads.prof=123456
The corresponding {{url.csid}} and {{url.prof}} macros in the ad tag URL will be replaced with the values provided. This approach is useful for third-party players, FAST channel integrations, or any scenario where you don't control the player SDK initialization.
How to Use Macro Variables
Step 1: Create an Ad Configuration
Create an SSAI ad configuration with macro placeholders in the ad server URL.
Request
POST https://api.live.brightcove.com/v2/accounts/{account_id}/ssai/ad-configs
Request Body
{
"description": "Sports Ad Configuration",
"ad_server": {
"url": "https://ads.example.com/ad?sid={{session.session_id}}&ip={{client.ipaddress}}&dur={{live.adbreakdurationms}}&category={{url.givn}}",
"response_type": "VAST",
"headers": {
"X-Api-Key": "your-api-key"
}
},
"custom_beacons": [
{
"event": "start",
"url": "https://tracking.example.com?event=start&session={{session.session_id}}&ad={{tracking.ad_id}}"
},
{
"event": "complete",
"url": "https://tracking.example.com?event=complete&session={{session.session_id}}&ad={{tracking.ad_id}}"
}
]
}
In this example:
{{session.session_id}},{{client.ipaddress}}, and{{live.adbreakdurationms}}are built-in macros that are automatically populated{{url.givn}}is a custom URL macro — the value is passed by the client during session initialization
Step 2: Create an SSAI-Enabled Job
Create a live job with SSAI enabled and select the ad configuration you created in Step 1. For more details, see the NextGen Live: Implementing Server-Side Ad Insertion document.
Step 3: Insert a Cuepoint
Insert a cuepoint to trigger an ad break in your live stream.
Request
POST https://api.live.brightcove.com/v2/accounts/{account_id}/jobs/{job_id}/cuepoint
Request Body
{
"duration_in_seconds": 60
}
To pass custom targeting parameters, add them to the playback URL query string:
https://playback.live.brightcove.com/v1/accounts/{account_id}/jobs/{job_id}/playlist.m3u8?givn=sports
Custom Beacons
Custom beacons allow you to track ad playback events. In NextGen Live, you configure custom beacons within the ad configuration using the custom_beacons field.
Supported Beacon Event Types
Core Linear Video Events
start- Ad startedfirstQuartile- 25% completemidpoint- 50% completethirdQuartile- 75% completecomplete- 100% complete
Additional Engagement Events
mute,unmutepause,resumerewind,skipprogress(with offset)
Non-linear & Companion Events
creativeViewcloseLinear,closeacceptInvitation,acceptInvitationLinearexpand,collapse
Example with Custom Beacons
{
"description": "Ad Config with Custom Beacons",
"ad_server": {
"url": "https://ads.example.com/ad",
"response_type": "VAST"
},
"custom_beacons": [
{
"event": "start",
"url": "https://tracking.example.com?event=start&session={{session.session_id}}&ad={{tracking.ad_id}}"
},
{
"event": "firstQuartile",
"url": "https://tracking.example.com?event=firstQuartile&session={{session.session_id}}&ad={{tracking.ad_id}}"
},
{
"event": "midpoint",
"url": "https://tracking.example.com?event=midpoint&session={{session.session_id}}&ad={{tracking.ad_id}}"
},
{
"event": "thirdQuartile",
"url": "https://tracking.example.com?event=thirdQuartile&session={{session.session_id}}&ad={{tracking.ad_id}}"
},
{
"event": "complete",
"url": "https://tracking.example.com?event=complete&session={{session.session_id}}&ad={{tracking.ad_id}}"
}
]
}
SCTE-35 Support
The Society of Cable Telecommunications Engineers (SCTE) defines a standard for dynamic ad insertion for live streams. An SCTE-35 ad marker defines the timestamp and duration where an ad can be inserted into the stream.
SCTE-35 parameters are automatically extracted from the live stream when using RTP or SRT input protocols and SCTE-35 has been enabled for the job.
Using SCTE-35 Macros
When your encoder sends SCTE-35 markers in the stream, the following macros are automatically populated:
{
"description": "Ad Config with SCTE-35 Macros",
"ad_server": {
"url": "https://ads.example.com/ad?event={{scte.event_id}}&avail={{scte.avail_num}}&archive={{scte.archive_allowed_flag}}",
"response_type": "VAST"
}
}
No additional API calls are needed - values are automatically extracted from the SCTE-35 binary data in the stream.
API Scope Requirements
To use the SSAI and cuepoint APIs, you need appropriate API credentials with the following scopes:
| Operation | Required Scope |
|---|---|
| Create ad config | video-cloud/livev2/ssai/create |
| List ad configs | video-cloud/livev2/ssai/read |
| Get ad config | video-cloud/livev2/ssai/read |
| Update ad config | video-cloud/livev2/ssai/update |
| Delete ad config | video-cloud/livev2/ssai/delete |
| Insert cuepoint | video-cloud/livev2/jobs/update |
| Create job | video-cloud/livev2/jobs/create |
For information on creating API credentials, see Managing API Authentication Credentials.