Campaign ID

This page covers data collection for the Campaign ID variable. See Campaign ID for the corresponding reporting dimension.

The campaign ID variable identifies the ad campaign that the creative belongs to. Any string value (typically a campaign ID from your ad-server platform) is acceptable. Use the variable to roll up engagement across multiple creatives that share a campaign.

Property
Value
Context data variable
a.media.ad.campaign
XDM collection field
xdm.mediaCollection.advertisingDetails.campaignID
Audience Manager trait
c_contextdata.a.media.ad.campaign
Required
No
Sent with
Ad start, ad close
Web SDK

Set campaignID inside xdm.mediaCollection.advertisingDetails when calling sendEvent:

code language-javascript
alloy("sendEvent", {
  xdm: {
    eventType: "media.adStart",
    mediaCollection: {
      advertisingDetails: {
        name: "ad-2125",
        campaignID: "fall-2024"
      },
      sessionID: "{sid}",
      playhead: 0
    }
  }
});
iOS

Pass the campaign ID as a metadata key in the HashMap argument to trackEvent(AdStart). Use MediaConstants.AdMetadataKeys.CAMPAIGN_ID.

code language-swift
var metadata: [String: String] = [:]
metadata[MediaConstants.AdMetadataKeys.CAMPAIGN_ID] = "fall-2024"

tracker.trackEvent(event: MediaEvent.AdStart, info: adObject, metadata: metadata)
Android

Pass the campaign ID as a metadata key in the HashMap argument to trackEvent(AdStart). Use MediaConstants.AdMetadataKeys.CAMPAIGN_ID.

code language-kotlin
val metadata = HashMap<String, String>()
metadata[MediaConstants.AdMetadataKeys.CAMPAIGN_ID] = "fall-2024"

tracker.trackEvent(Media.Event.AdStart, adObject, metadata)
Roku Edge

Set campaignID inside xdm.mediaCollection.advertisingDetails when calling sendMediaEvent for media.adStart:

code language-brightscript
m.aepSdk.sendMediaEvent({
    "xdm": {
        "eventType": "media.adStart",
        "mediaCollection": {
            "advertisingDetails": {
                "name": "ad-2125",
                "campaignID": "fall-2024"
            },
            "playhead": 0
        }
    }
})
Media Edge API

Call the adStart endpoint with campaignID inside xdm.mediaCollection.advertisingDetails:

code language-json
{
  "events": [{
    "xdm": {
      "eventType": "media.adStart",
      "mediaCollection": {
        "advertisingDetails": {
          "name": "ad-2125",
          "length": 15,
          "playerName": "Freewheel",
          "podPosition": 0,
          "campaignID": "fall-2024"
        },
        "sessionID": "{sid}",
        "playhead": 0
      }
    }
  }]
}

Legacy implementation types (Analytics-only)

Media SDK JS 3.x

Pass the campaign ID in the contextData object using ADB.Media.AdMetadataKeys.CampaignId:

code language-javascript
var contextData = {};
contextData[ADB.Media.AdMetadataKeys.CampaignId] = "fall-2024";

tracker.trackEvent(ADB.Media.Event.AdStart, adInfo, contextData);
Chromecast

Set the campaign ID using ADBMobile.media.AdMetadataKeys.CAMPAIGN_ID in the standard ad metadata object:

code language-javascript
var adInfo = ADBMobile.media.createAdObject("Ford F-150", "ad-2125", 1, 30);
var standardAdMetadata = {};
standardAdMetadata[ADBMobile.media.AdMetadataKeys.CAMPAIGN_ID] = "fall-2024";
adInfo[ADBMobile.media.MediaObjectKey.StandardAdMetadata] = standardAdMetadata;
ADBMobile.media.trackEvent(ADBMobile.media.Event.AdStart, adInfo, null);
Roku 2.x

Set the campaign ID using MEDIA_AdMetadataKeyCAMPAIGN_ID in the standard ad metadata object:

code language-brightscript
adb = ADBMobile()
adInfo = adb_media_init_adinfo("Ford F-150", "ad-2125", 1, 30.0)

standardAdMetadata = {}
standardAdMetadata[adb.MEDIA_AdMetadataKeyCAMPAIGN_ID] = "fall-2024"
adInfo[adb.MEDIA_STANDARD_AD_METADATA] = standardAdMetadata

adb.mediaTrackEvent(adb.MEDIA_AD_START, adInfo)
Media Collection API

Include media.ad.campaignId in the params object:

code language-json
{
  "playerTime": { "playhead": 0, "ts": 1699523820000 },
  "eventType": "adStart",
  "params": {
    "media.ad.campaignId": "fall-2024"
  }
}

See the Media Collection API events reference for the full request structure.

recommendation-more-help
media-analytics-help