Video
Big Crunch instream video ad units are designed for publisher-owned video players. You keep control of the player and the Google IMA integration; Big Crunch supplies the ad tag (VAST URL) and records impressions and viewability for your reporting.
Requirements
- A Big Crunch instream video ad unit (see below).
- The Big Crunch Lighthouse script installed on the page.
- A video player integrated with the Google IMA HTML5 SDK.
- Access to the IMA
adsManagerand the ad container element.
Set Up an Instream Ad Unit
Create the ad unit in Big Crunch before adding any code to your player:
- Add a new ad unit and choose the Instream Video type.
- Set the GAM ad unit path. This is required — Big Crunch uses it to build the ad tag, and requests fail without it.
- Add one or more player sizes (for example
640×360). Your player can request one of these at runtime, or let Big Crunch send all of them. - Set the VAST defaults — ad break position, placement, ad format, autoplay, muted playback, ad durations, and companion sizes. These apply to every request unless your player overrides them.
- Enable the ad unit and deploy your website.
content_preroll).Request an Ad Tag
Call getVastUrl when the player is ready to request an ad. Pass the ad unit code and any values you want to set for this request, then hand the returned URL to IMA as the ad tag URL.
If the ad unit can't serve — it's missing, disabled, or required consent isn't available — the promise rejects. Catch it, skip the ad request, and play your content.
try {
const vastUrl = await window.bigcrunch.instreamVideo.getVastUrl(
"content_preroll",
{
description_url: location.href,
playerSize: [640, 360],
vpos: "preroll"
}
);
const adsRequest = new google.ima.AdsRequest();
adsRequest.adTagUrl = vastUrl;
adsRequest.linearAdSlotWidth = 640;
adsRequest.linearAdSlotHeight = 360;
adsRequest.nonLinearAdSlotWidth = 640;
adsRequest.nonLinearAdSlotHeight = 150;
adsLoader.requestAds(adsRequest);
} catch {
playContentVideo();
}playerSize is optional when the ad unit already has sizes configured — passing it per request just overrides the defaults. Always set description_url to the page or video URL. If you omit it, Big Crunch falls back to the page the player is on, but you should set it explicitly so demand partners receive the correct content URL.
Bind IMA Events
Bind Big Crunch after IMA returns an adsManager. Big Crunch records one impression when IMA reports the ad has started, and measures viewability against the ad container.
adsLoader.addEventListener(
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
function (event) {
const adsManager = event.getAdsManager(contentVideoElement);
const unbindBigCrunch = window.bigcrunch.instreamVideo.bindImaEvents(
"content_preroll",
adsManager,
{
playerSize: [640, 360],
viewabilityElement: adContainerElement
}
);
adsManager.addEventListener(
google.ima.AdEvent.Type.ALL_ADS_COMPLETED,
unbindBigCrunch
);
adsManager.init(640, 360, google.ima.ViewMode.NORMAL);
adsManager.start();
}
);Viewability
Big Crunch records one viewability event once the ad is playing and the container has been at least 50% visible for two seconds. Pass the element your player uses for the ad as viewabilityElement, or a CSS selector as viewabilitySelector.
You can adjust the threshold and duration with viewabilityThreshold and viewabilityDurationMs if you need different rules. Google's own Active View measurement keeps running inside IMA for GAM / AdX reporting either way.
Mid-Roll and Post-Roll
For manual ad breaks, request a fresh ad tag for each break. Big Crunch generates a new request each time.
const midrollUrl = await window.bigcrunch.instreamVideo.getVastUrl(
"content_midroll",
{
description_url: location.href,
playerSize: [640, 360],
vpos: "midroll"
}
);
const postrollUrl = await window.bigcrunch.instreamVideo.getVastUrl(
"content_postroll",
{
description_url: location.href,
playerSize: [640, 360],
vpos: "postroll"
}
);If you'd rather have Google return the whole break schedule in one response, turn on Ad rules on the ad unit (or pass ad_rule: true). Big Crunch then requests a VMAP playlist instead of a single ad tag.
Runtime Overrides
The ad unit stores default VAST settings. Your player can override any of them per request. The most common:
description_url- the canonical page or video URL.playerSize- one size such as[640, 360]or a configured size string such as"640x360".vpos-"preroll","midroll", or"postroll".vad_type-"linear"for preroll-style video ads, or"nonlinear"for overlay ads.cust_paramsorcustomParams- GAM custom targeting key-values.
You can also override plcmt, vpa, vpmute, min_ad_duration, max_ad_duration, sdmax, ad_rule, and ciu_szs — each maps to the matching default on the ad unit.
Test Ads
For local development, create a separate instream video ad unit that points at the GAM sample or test VAST iu, then choose that ad unit code in non-production environments. This keeps production demand settings out of publisher code while preserving the same integration.
const adUnitCode = isLocal ? "content_preroll_test" : "content_preroll";
const vastUrl = await window.bigcrunch.instreamVideo.getVastUrl(adUnitCode, {
description_url: location.href,
playerSize: [640, 360],
customParams: isLocal ? { sample_ct: "linear" } : undefined
});Debugging
- Confirm the page loads the Big Crunch Lighthouse script before the player requests ads.
- Inspect the network request to
/gampad/adsand verifyiu(your GAM ad unit path),sz(player size), anddescription_url. Consent signals are added automatically. - Confirm the IMA ad-started /
IMPRESSIONevent fires for theadsManager. - Check for Big Crunch requests to
/impressionsand/viewability. - For Google Active View, inspect requests to
pagead2.googlesyndication.com/pcs/activeview.