UNPKG

@theoplayer/react-native-analytics-comscore

Version:
168 lines (159 loc) 7.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AdMetadata = void 0; var _Utils = require("./Utils"); var analytics = _interopRequireWildcard(require("./sdk/comscore")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /* eslint-disable @typescript-eslint/no-inferrable-types */ class AdMetadata { /** * Stores ns_.analytics.StreamingAnalytics.AdvertisementMetadata() * * @private * @type {*} * @memberof AdMetadata */ /** * sets ad metadata * @param {Boolean} isAudio Use value true if the advertisement is audio-only, rather than video (with or without audio). Otherwise omit or use value false, Comscore API: classifyAsAudioStream( Boolean value ) * @param {Object} customLabels a collection of custom metadata name/value pair, Comscore API: addCustomLabels( Object labels ) * @param {analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementDeliveryType} deliveryType Specify the mechanism use to deliver an advertisement, Comscore API: setDeliveryType( value ) * @param {analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementOwner} owner Specify who is monetizing the advertisement, Comscore API: setOwner( value ) * @param {String} serverCampaignId Provide an ID for the advertisement campaign being delivered, Comscore API: setServerCampaignId( String id ) * @param {String} placementId Provide an ID for the placement the advertisement campaign is being delivered to, Comscore API: setPlacementId( String id ) * @param {String} siteId Provide an ID for the site the advertisement campaign is being delivered to, Comscore API: setSiteId( String id ) * @param {String} serverName Provide a name for the advertising server/provider, Comscore API: setServer( String name ) * @param {String} title Provide a title for the advertisement (i.e., the name of the campaign or creative), Comscore API: setTitle( String title ) * @param {String} callToActionUrl Provide the URL which will be loaded when the advertisement is clicked on, Comscore API: setCallToActionUrl( String url ) * @param {String} clipUrl The URL (or path/filename) of the advertisement stream, Comscore API: setClipUrl( String url ) * @param {Number} pixelsWide Advertisement video width, Comscore API: setVideoDimensions( int pixelsWide, int pixelsHigh ) * @param {Number} pixelsHigh Advertisement video height, Comscore API: setVideoDimensions( int pixelsWide, int pixelsHigh ) */ constructor(isAudio = false, customLabels = null, deliveryType = null, owner = null, serverCampaignId = null, placementId = null, siteId = null, serverName = null, title = null, callToActionUrl = null, clipUrl = null, pixelsWide = 0, pixelsHigh = 0) { const cm = new analytics.StreamingAnalytics.AdvertisementMetadata(); if (deliveryType) { cm.setDeliveryType(deliveryType); } if (owner) { cm.setOwner(owner); } cm.classifyAsAudioStream(isAudio); if (serverCampaignId) { cm.setServerCampaignId(serverCampaignId); } if (placementId) { cm.setPlacementId(placementId); } if (siteId) { cm.setSiteId(siteId); } if (serverName) { cm.setServer(serverName); } if (title) { cm.setTitle(title); } if (callToActionUrl) { cm.setCallToActionUrl(callToActionUrl); } if (clipUrl) { cm.setClipUrl(clipUrl); } if (pixelsWide && pixelsHigh) { cm.setVideoDimensions(pixelsWide, pixelsHigh); } if (customLabels) { cm.addCustomLabels(customLabels); // Can be used to specify a collection of custom metadata name/value pairs. } this.cm = cm; } /** * Sets media type based on ad type and if stream is live * @param adType ad type: preroll, midroll, postroll * @param isLive specifies if stream is LIVE */ setMediaType(adType, isLive) { const { ON_DEMAND_PRE_ROLL, ON_DEMAND_MID_ROLL, ON_DEMAND_POST_ROLL, LIVE } = analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType; let cm_AdType = adType; if (isLive) { cm_AdType = LIVE; //this.cm.setMediaType(LIVE); } else { switch (adType) { case _Utils.AD_TYPES.PREROLL: cm_AdType = ON_DEMAND_PRE_ROLL; //this.cm.setMediaType(ON_DEMAND_PRE_ROLL); break; case _Utils.AD_TYPES.MIDROLL: cm_AdType = ON_DEMAND_MID_ROLL; //this.cm.setMediaType(ON_DEMAND_MID_ROLL); break; case _Utils.AD_TYPES.POSTROLL: cm_AdType = ON_DEMAND_POST_ROLL; //this.cm.setMediaType(ON_DEMAND_POST_ROLL); break; default: break; } } //FIX issue 12 17 19 (0, _Utils.logDebug)('AdMetadata - setMediaType', cm_AdType); this.cm.setMediaType(cm_AdType); } /** * sets the analytics.StreamingAnalytics.ContentMetadata of the content which the advertisement is served for. Omit for cases where player is not aware which content the advertisement is playing for. * @param {ContentMetadata} relatedContent , Comscore API: setRelatedContentMetadata(contentMetadataObject ) */ setRelatedContentMetadata(relatedContent) { (0, _Utils.logDebug)('AdMetadata - setRelatedContentMetadata', relatedContent.getContentMetadata()); this.cm.setRelatedContentMetadata(relatedContent.getContentMetadata()); } /** * Sets a unique identifier of the advertisement * @param uniqueId a unique identifier of the advertisement Comscore API: setUniqueId( String id ) * @memberof AdMetadata */ setId(uniqueId) { const id = uniqueId || '*null'; (0, _Utils.logDebug)('AdMetadata - setId', id); this.cm.setUniqueId(id); } /** * sets duration of ad * @memberof AdMetadata, Comscore API: setLength( int length ) */ setLength(length) { (0, _Utils.logDebug)('AdMetadata - setLength', length); this.cm.setLength(length); } /** * set Custom Auditel labels * @param {String} oce_skp Advertisement's skippable duration, Adv: Mandatory * @memberof ContentMetadata */ addCustomLabels(oce_skp) { let customLabels; if (oce_skp) { customLabels.oce_skp = oce_skp; } (0, _Utils.logDebug)('AdMetadata - addCustomLabels', customLabels); this.cm.addCustomLabels(customLabels); } /** * Gets content metadata * @readonly * @memberof AdContentMetadata */ getAdContentMetadata() { return this.cm; } static clone(old) { return new AdMetadata(old.cm.isAudio, old.cm.customLabels, old.cm.deliveryType, old.cm.owner, old.cm.serverCampaignId, old.cm.placementId, old.cm.siteId, old.cm.serverName, old.cm.title, old.cm.callToActionUrl, old.cm.clipUrl, old.cm.pixelsWide, old.cm.pixelsHigh); } } exports.AdMetadata = AdMetadata; //# sourceMappingURL=ComscoreAdMetadata.js.map