Skip to content
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
12 changes: 11 additions & 1 deletion extensions/lib_books/set_mediaID_from_contentID
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//Runs only on Tealium link events for video interactions.
// Ensures contentID is present before extracting media_id.

(function (a, b) {

// Only run on link events where event_name === "video"
Expand All @@ -8,14 +9,23 @@
}

// Get contentID from data layer
var cid = utag.data.contentID;
var cid = b.contentID || utag.data.contentID;

// Validate contentID
if (!cid || typeof cid !== "string") return;

// Clean stray quotes/spaces
cid = cid.trim().replace(/^\"+|\"+$/g, "");

// Always set media_type for video events (keeps legacy behavior for non-live)
if (cid.indexOf("personalstream") > -1) {
b.media_type = "video : 24/7 live";
} else {
b.media_type = "video"; // keep existing value so reports don’t change
}
utag.data.media_type = b.media_type;


var mediaID;

// Extract media ID based on content-discovery pattern
Expand Down
67 changes: 67 additions & 0 deletions tests/lib_books/set_mediaID_from_contentID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,73 @@ describe('set_mediaID_from_contentID - Video Media ID Extraction', () => {
jest.clearAllMocks();
});

describe('Media type classification (live vs default)', () => {
it('should set media_type to live when contentID contains "personalstream"', () => {
// Arrange
global.a = 'link';
global.b = { event_name: 'video' };
global.utag.data.contentID = 'https://petbook.personalstream.tv/v1/master.m3u8';

// Act
jest.isolateModules(() => {
require('../../extensions/lib_books/set_mediaID_from_contentID');
});

// Assert
expect(global.b.media_type).toBe('video : 24/7 live');
expect(global.utag.data.media_type).toBe('video : 24/7 live');
});

it('should set media_type to default "video" when contentID does not contain "personalstream"', () => {
// Arrange
global.a = 'link';
global.b = { event_name: 'video' };
global.utag.data.contentID = '/category/subcategory/article789/extra';

// Act
jest.isolateModules(() => {
require('../../extensions/lib_books/set_mediaID_from_contentID');
});

// Assert
expect(global.b.media_type).toBe('video');
expect(global.utag.data.media_type).toBe('video');
});

it('should not set media_type if event type is not link', () => {
// Arrange
global.a = 'view';
global.b = { event_name: 'video' };
global.utag.data.contentID = 'https://petbook.personalstream.tv/v1/master.m3u8';

// Act
jest.isolateModules(() => {
require('../../extensions/lib_books/set_mediaID_from_contentID');
});

// Assert
expect(global.b.media_type).toBeUndefined();
expect(global.utag.data.media_type).toBeUndefined();
});

it('should not set media_type if event_name is not video', () => {
// Arrange
global.a = 'link';
global.b = { event_name: 'click' };
global.utag.data.contentID = 'https://petbook.personalstream.tv/v1/master.m3u8';

// Act
jest.isolateModules(() => {
require('../../extensions/lib_books/set_mediaID_from_contentID');
});

// Assert
expect(global.b.media_type).toBeUndefined();
expect(global.utag.data.media_type).toBeUndefined();
});
});


describe('When video link event with content-discovery pattern', () => {
it('should extract media_id from position [4] for content-discovery URLs', () => {
// Arrange
Expand Down
Loading