Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/conviva adbegin error #43

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-zoos-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@theoplayer/conviva-connector-web": patch
---

Fixed an issue where we could throw an error for non Google-IMA ads.
11 changes: 10 additions & 1 deletion conviva/src/integration/ads/AdReporter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { Ad, AdBreak, ChromelessPlayer, GoogleImaAd } from 'theoplayer';
import { type AdAnalytics, Constants, type ConvivaMetadata, type VideoAnalytics } from '@convivainc/conviva-js-coresdk';
import { calculateAdType, calculateCurrentAdBreakInfo, collectAdMetadata, collectPlayerInfo } from '../../utils/Utils';
import {
calculateAdType,
calculateCurrentAdBreakInfo,
collectAdMetadata,
collectPlayerInfo,
updateAdMetadataForGoogleIma
} from '../../utils/Utils';

export class AdReporter {
private readonly player: ChromelessPlayer;
Expand Down Expand Up @@ -47,6 +53,9 @@ export class AdReporter {
return;
}
const adMetadata = collectAdMetadata(currentAd);
if (currentAd.integration === 'google-ima') {
updateAdMetadataForGoogleIma(currentAd as GoogleImaAd, adMetadata);
}

// Every session ad or content has its session ID. In order to “attach” an ad to its respective content session,
// there are two tags that are critical:
Expand Down
34 changes: 29 additions & 5 deletions conviva/src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,39 @@ export function collectVerizonAdMetadata(ad: VerizonMediaAd): ConvivaMetadata {
return adMetadata;
}

export function updateAdMetadataForGoogleIma(ad: GoogleImaAd, metadata: ConvivaMetadata): ConvivaMetadata {
const adMetadata = metadata;
const streamUrl = ad.mediaUrl;
if (streamUrl) {
adMetadata[Constants.STREAM_URL] = streamUrl;
}
const assetName = ad.title;
if (assetName) {
adMetadata[Constants.ASSET_NAME] = assetName;
adMetadata['c3.ad.creativeName'] = assetName;
}
if (ad.wrapperAdIds[0]) {
adMetadata['c3.ad.firstAdId'] = ad.wrapperAdIds[0];
}
if (ad.wrapperCreativeIds[0]) {
adMetadata['c3.ad.firstCreativeId'] = ad.wrapperCreativeIds[0];
}
if (ad.wrapperAdSystems[0]) {
adMetadata['c3.ad.firstAdSystem'] = ad.wrapperAdSystems[0];
}

return adMetadata;
}

export function collectAdMetadata(ad: Ad): ConvivaMetadata {
const adMetadata: ConvivaMetadata = {
[Constants.DURATION]: ad.duration as any
};
const streamUrl = (ad as GoogleImaAd).mediaUrl || ad.resourceURI;
const streamUrl = ad.resourceURI;
if (streamUrl) {
adMetadata[Constants.STREAM_URL] = streamUrl;
}
const assetName = (ad as GoogleImaAd).title || ad.id;
const assetName = ad.id;
if (assetName) {
adMetadata[Constants.ASSET_NAME] = assetName;
}
Expand Down Expand Up @@ -160,19 +184,19 @@ export function collectAdMetadata(ad: Ad): ConvivaMetadata {
// This tag must capture the "first" Ad Id in the wrapper chain when a Linear creative is available or there is
// an error at the end of the wrapper chain. Set to "NA" if not available. If there is no wrapper VAST response
// then the Ad Id and First Ad Id should be the same.
adMetadata['c3.ad.firstAdId'] = (ad as GoogleImaAd).wrapperAdIds[0] || ad.id || 'NA';
adMetadata['c3.ad.firstAdId'] = ad.id || 'NA';

// [Preferred] Only valid for wrapper VAST responses.
// This tag must capture the "first" Creative Id in the wrapper chain when a Linear creative is available or
// there is an error at the end of the wrapper chain. Set to "NA" if not available. If there is no wrapper
// VAST response then the Ad Creative Id and First Ad Creative Id should be the same.
adMetadata['c3.ad.firstCreativeId'] = (ad as GoogleImaAd).wrapperCreativeIds[0] || ad.creativeId || 'NA';
adMetadata['c3.ad.firstCreativeId'] = ad.creativeId || 'NA';

// [Preferred] Only valid for wrapper VAST responses. This tag must capture the "first" Ad System in the wrapper
// chain when a Linear creative is available or there is an error at the end of the wrapper chain. Set to "NA" if
// not available. If there is no wrapper VAST response then the Ad System and First Ad System should be the same.
// Examples: "GDFP", "NA".
adMetadata['c3.ad.firstAdSystem'] = (ad as GoogleImaAd).wrapperAdSystems[0] || ad.adSystem || 'NA';
adMetadata['c3.ad.firstAdSystem'] = ad.adSystem || 'NA';

// The name of the Ad Stitcher. If not using an Ad Stitcher, set to "NA"
adMetadata['c3.ad.adStitcher'] = 'NA';
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.