Skip to contentSkip to navigationSkip to topbar
On this page
Looking for more inspiration?Visit the
(information)
You're in the right place! Segment documentation is now part of Twilio Docs. The content you are used to is still here—just in a new home with a refreshed look.

Analytics Swift Nielsen DCR Plugin


Nielsen Digital Content Ratings (DCR) respond to the shifting and complex multi-platform, multi-device, and multi-distribution landscape by providing comprehensive measurement of digital content consumption—including streaming video, static web pages and mobile apps—across all major devices and platforms. The Analytics-Swift Nielsen-DCR Plugin(link takes you to an external page) tracks sessions via for Analytics-Swift(link takes you to an external page).


Getting started

getting-started page anchor

To get started with Nielsen-DCR and retrieve an appid to configure this integration, you must complete the following prerequisite steps with Nielsen:

  • Fill out your company info and work with a Nielsen representative.
  • Sign a license agreement on the Nielsen engineering portal.
  • Sign an NDA to sign prior to accessing the download.
  • Complete a pre-certification process with your Nielsen representative before shipping this implementation to production.
(success)

Success!

This plugin simply adds session data for Nielsen-DCR, and events are sent via Cloud Mode.


via Xcode

via-xcode page anchor

In the Xcode File menu, click Add Packages. You'll see a dialog where you can search for Swift packages. In the search field, enter the URL to this repo.

https://github.com/segment-integrations/analytics-swift-nielsen-dcr

You then have the option to pin to a version or specific branch and select which project in your workspace to add the package to. Once you've made your selections, click the Add Package button.

Open your Package.swift file and add the following to the dependencies section:

1
.package(
2
name: "Segment",
3
url: "https://github.com/segment-integrations/analytics-swift-nielsen-dcr.git",
4
from: "1.0.0"
5
),

Using the plugin in your aPp

using-the-plugin-in-your-app page anchor

Open the file where you set up and configured the Analytics-Swift library. Add this plugin to the list of imports.

1
import Segment
2
import SegmentNielsenDCR // <-- Add this line

Under your Analytics-Swift library setup, call analytics.add(plugin: ...) to add an instance of the plugin to the Analytics timeline.

1
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
2
.flushAt(3)
3
.trackApplicationLifecycleEvents(true))
4
analytics.add(plugin: NielsenDCRDestination())

Your events now contain Nielsen-DCR session data and flow to Nielsen-DCR in device-mode.


Segment supports translating Screen or Page to Nielsen as a Static App Measurement event. Segment translates the following properties to the expected Nielsen metadata:

Segment Property NameNielsenNielsen Description
typetypeRequired. Segment hardcodes 'static'
name*sectionRequired. Section of site
integration optionsegBRequired (optional for web). Segment A.
integration optionsegCRequired (optional for web). Segment B.
integration optioncrossId1Standard episode ID (mobile only)

* On web and mobile, you can map a custom property to section using the Custom Page/Screen Section Property Name setting. If this setting is left blank, Segment will fallback on the top-level name.


Segment only supports sending Track events as outlined in the Video Spec. To get started tracking video content through Segment, make sure you are using a media player that has an API which allows you to detect the player state such as video or ad plays. For example, you would not be able to collect ad plays using YouTube since their YouTube SDK does not expose any hooks into player states during ad plays.

(warning)

Make sure you implement the Video Spec correctly

If you do not implement the Segment Video Spec properly with key lifecycle events, this integration will not behave properly.

Again, also refer to the Video Spec and implement video tracking as outlined there. Segment maps the semantic events and properties to Nielsen's relevant methods and metadata.

Nielsen expects a heartbeat called with playheadPosition during session play every second until the stream is completed, paused or interrupted (due to ad breaks or buffering). The playhead position is the current location in seconds of the playhead from the beginning of the asset. For livestream, Segment expects a negative integer that represents the offset in seconds in relation to the current timestamp. For example, if content is being livestreamed at 8PM but the viewer is 30 seconds behind, the value of this property should be -30. You can override this and pass the current time in seconds to Nielsen by toggling the Enable Default to Current Time for Livestream Playhead Position setting.

Segment will set a timer to call this heartbeat event (–(void) playheadPosition: (long long) playheadPos), setTimeout (web)) every second in background. You do not have to call the Segment equivalent heartbeat event (Video Content/Ad Playing) each second. You should follow the spec and call the Segment heartbeat event every 10 seconds (recommended). While Segment keeps the state of its playhead position for these background hearbeats, when Segment receives an explicit heartbeat event, Segment respects its properties.position and restarts the background heartbeats from that position.

When you call Video Playback Started and Video Playback Resumed, Segment calls the Nielsen-DCR play method with the relevant channelInfo:

1
NSDictionary *channelInfo = @{
2
// channelName is optional for DCR, if not present Nielsen asks to set default
3
@"channelName" : options[@"channelName"] ?: @"defaultChannelName",
4
// if mediaURL is not available, Nielsen expects an empty value
5
@"mediaURL" : options[@"mediaUrl"] ?: @""
6
};
7
(void) play: (id) channelInfo;
8

From there, Segment maps to the relevant events on the instance:

Nielsen-DCR SpecSegment Video Spec
–(void) stop and Heartbeat timer stoppedVideo Playback Paused
–(void) stop and Heartbeat timer stoppedVideo Playback Interrupted
Heartbeat timer stoppedVideo Playback Buffer Started
Heartbeat timer updatedVideo Playback Buffer Completed
Heartbeat timer stoppedVideo Playback Seek Started
Heartbeat timer updatedVideo Playback Seek Completed
-(void) end and Heartbeat timer stoppedVideo Playback Completed

For playback events, Segment's video spec expects either ad_asset_id​ or content_asset_id​ depending on whether the video is an ad or content. Segment will default to mapping ad_asset_id to Nielsen's ad metadata assetid and content_asset_id to Nielsen's content metadata. The default Segment property can be overridden in your integration settings: Custom Content Asset Id Property Name or Custom Ad Asset Id Property Name.

Nielsen-DCR SpecSegment Video Spec
–(void)loadMetadata:(id)metadata;Video Content Started
Heartbeat timer updatedVideo Content Playing
–(void) end and -(void) stopVideo Content Completed

Content Properties (Labels)

Nielsen-DCR metadataSegment Property
assetidasset_id
programprogram
titletitle
segBoptions.segB
segCoptions.segC
airdateairdate
isfullepisodefull_episode
lengthtotal_length
pipmodeoptions.pipmode
type'content' (hardcoded)
adLoadTypeoptions.adLoadType
hasAdsoptions.hasAds
crossId1options.crossId1
crossId2options.crossId2

camelCase is expected for Android.

The Segment-Nielsen-DCR integration has logic to check for type in case of a preroll ad. If the type is preroll, Segment calls Nielsen's loadMetadata method with metadata values for content followed by loadMetadata with ad (preroll) metadata. Otherwise, Segment simply calls loadMetadata with the ad metadata.

Nielsen-DCR SpecSegment Video Spec
–(void)loadMetadata:(id)metadata; and Heartbeat timer startedVideo Ad Started
Heartbeat timer updatedVideo Ad Playing
–(void) stop and Heartbeat timer stoppedVideo Ad Completed
Nielsen-DCR Ad metadataSegment Property
assetidasset_id
typetype
titletitle
Nielsen-DCR Ad Content metadataSegment Property
assetidasset_id
adloadtypeoptions.ad_load_type
typecontent (hard coded)
titletitle
programprogram
segBoptions.segB
segCoptions.segC
airdateairdate
isfullepisodefull_episode
lengthtotal_length
pipmodeoptions.pipmode

camelCase is expected for Android.


Integration specific options

integration-specific-options page anchor

See the following example for passing destination specific values in Swift:

1
let options: [String: Any] = [
2
"integrations": [
3
"nielsen-dcr": [
4
"pipmode": "2017-05-22",
5
"adLoadType": "c3 value",
6
"channelName": "c4 value",
7
"mediaUrl": "c6 value",
8
"hasAds": true,
9
"crossId1": "cross id1 value",
10
"crossId2": "cross id2 value"
11
]
12
]
13
]

PiP mode

pip-mode page anchor

Current state of picture-in-picture (PiP) mode on device. Pass in true if the video measurement is displayed in PiP mode. Otherwise, Segment defaults to false if no value is present.

Type of ad load. Pass in dynamic to indicate Dynamic Ad Insertion (DAI). Otherwise, Segment defaults to linear.

Channel name and media URL

channel-name-and-media-url page anchor

The SDK is started by calling the play API with the channelName and mediaURL parameters. If no value is passed in, Segment defaults to defaultChannelName for channelName and an empty String for mediaURL.

Standard episode ID.

Content originator ID. This value is only required for distributors.


How do you determine app name?

how-do-you-determine-app-name page anchor

For Android, Segment retrieves the name of the application package from the PackageManager(link takes you to an external page).

How do you determine app version?

how-do-you-determine-app-version page anchor

Segment-Nielsen-DCR retrieves the application version from your app's Info.plist application bundle name as returned by CFBundleVersion.

For Android, Segment retrieves the version of the application package from the PackageManager(link takes you to an external page).

What are the Nielsen-DCR clientId and subbrand values?

what-are-the-nielsen-dcr-clientid-and-subbrand-values page anchor

The Parent Client ID and Sub-Brand (VCID) values are automatically populated through the AppID, which is Nielsen Supplied. By default, clientid and subbrand are set up in Nielsen backend configuration to capture brand and sub-brand information. The fields get populated from backend for a registered client appid.

Can I override the Nielsen-DCR clientId and subbrand values?

can-i-override-the-nielsen-dcr-clientid-and-subbrand-values page anchor

In the event that your app contains multiple brands and sub-brands, Segment lets you override the clientId and subbrand values, to give credit to another brand or sub-brand. In your Segment dashboard, under "Client Id Property Name", indicate a payload property to be mapped to the Nielsen clientId. To override a subbrand, indicate a payload property to mapped to Nielsen subbrand under "Subbrand Property Name".