Skip to content

Commit

Permalink
Disabled queue and ads from default implementation. Updated backend f…
Browse files Browse the repository at this point in the history
…etching mechanism.

Change-Id: Ic88523f157879b40ef77ba41c7385c29f61d9bfc
  • Loading branch information
gomez-andres committed Jul 28, 2022
1 parent 51745fa commit d6a2fe0
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 169 deletions.
4 changes: 2 additions & 2 deletions css/receiver.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 Google LLC. All Rights Reserved.
/**
Copyright 2022 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
13 changes: 7 additions & 6 deletions js/agents/google_analytics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Google LLC. All Rights Reserved.
/**
Copyright 2022 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

'use_strict';

/**
* Contains the initialization of the google analytics agent for use
* in the CastAnalytics sample.
* Initializes the google analytics agent for use in the receiver sample. To
* enable the functionality uncomment the call to google analytics below and
* provide your property's
* [trackingId](https://support.google.com/analytics/answer/9539598).
*/
'use_strict';

export function initGoogleAnalytics() {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
121 changes: 81 additions & 40 deletions js/cast_analytics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Google LLC. All Rights Reserved.
/**
Copyright 2022 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,20 +16,18 @@ limitations under the License.

'use_strict';

/**
* This sample demonstrates how to acquire and send Cast information to
* different analytics services
*/

// Imports a mapping of event types for easier reference
import { CastEventType, EventOwner } from './cast_event_types.js';
import { initGoogleAnalytics } from './agents/google_analytics.js';

/**
* Initialize any analytics provider tracking agents.
* @fileoverview This sample demonstrates how to acquire and send Cast
* information to analytics services such as Google Analytics.
*/
import { initGoogleAnalytics } from './agents/google_analytics.js';
initGoogleAnalytics();

/*
* Initialize the Google Analytics agent.
*/
initGoogleAnalytics();

/**
* Modules that handle Cast SDK events. The Tracker class is a template for its
Expand Down Expand Up @@ -70,23 +68,24 @@ class Tracker {
}

/**
* Template event handler that should be overidden in the child object.
* @param {cast.framework.events.*} event
* Template event handler that should be overidden by implementing classes.
* @param {cast.framework.events.EventType|cast.framework.system.EventType}
* event The event fired by the SDK to be handled by the tracker.
*/
handleEvent(event) {}

/**
* Template event sender that should be overidden in the child object.
* Template event sender that should be overidden by implementing classes.
* Sends the data collected from the event handler to the target analytics
* service providers.
* @param {Object} data The data to be sent to analytics provider backends.
*/
sendData(data) {}
}

/**
* Child of the tracker class used to handle ad related events and send them to
* an analytics service. Event data tracked includes quartile ad events, ad
* loading time, and break tracking.
* Handles ad related events and send them to an analytics service. Event data
* tracked includes quartile ad events, ad loading time, and break tracking.
*/
class AdsTracker extends Tracker {
constructor() {
Expand Down Expand Up @@ -116,11 +115,12 @@ class AdsTracker extends Tracker {

/**
* Handles the incoming event if it is a break event type or time update
* while the break is started. When a time update is detected the type is
* while the break is started. When a time update is detected, the type is
* modified to create a custom quartile event with added break and breakClip
* id for additional context.
* @param {cast.framework.events.BreaksEvent
* |cast.framework.events.BreaksEvent.MediaElementEvent} event
* @param {cast.framework.events.BreaksEvent|
* cast.framework.events.BreaksEvent.MediaElementEvent} event
* @override
*/
handleEvent(event) {
// Ignore event if the event is not a break started event
Expand All @@ -131,7 +131,7 @@ class AdsTracker extends Tracker {
return;
}

// Control the state of the tracker and send data if break has begun
// Control the state of the tracker and send data if break has begun.
switch (event.type) {
case CastEventType.TIME_UPDATE.event:
this.handleTimeUpdate(event);
Expand All @@ -148,23 +148,28 @@ class AdsTracker extends Tracker {
}
}

// Handle the break started event. Set flag to begin tracking relevant events.
/**
* Handle the break started event. Set flag to begin tracking relevant ad
* break events.
* @param {cast.framework.events.EventType.BREAK_STARTED} event
*/
handleBreakStarted(event) {
let data = {};
this.breakStarted = true;
this.breakId = event.breakId;

data.action = event.type;
data.id = event.breakId;

// Adobe Agent specific values
data.startTime = event.currentMediaTime;
data.position = event.index;

this.sendData(data);
}

// Handle time update event. Used to report quartile ad events.
/**
* Handle time update event. Used to report quartile ad events.
* @param {cast.framework.events.EventType.TIME_UPDATE} event
*/
handleTimeUpdate(event) {
let data = {};
let currTime = this.breakManager.getBreakClipCurrentTimeSec();
Expand All @@ -186,7 +191,10 @@ class AdsTracker extends Tracker {
this.sendData(data);
}

// Handle break clip started event. Sets up quartile ad tracking.
/**
* Handle break clip started event. Sets up quartile ad tracking.
* @param {cast.framework.events.EventType.BREAK_CLIP_STARTED} event
*/
handleBreakClipStarted(event) {
let data = {};
this.breakClipStarted = true;
Expand All @@ -199,16 +207,17 @@ class AdsTracker extends Tracker {

data.id = this.breakClipId;
data.action = event.type;

// Adobe Agent specific values.
data.position = event.index;
data.length = this.breakClipLength;


this.sendData(data);
}

// Handle break clip ended event. Resets quartile ad tracking.
/**
* Handle break clip ended event. Resets quartile ad tracking.
* @param {cast.framework.events.EventType.BREAK_CLIP_ENDED} event
*/
handleBreakClipEnded(event) {
let data = {};
data.id = this.breakClipId;
Expand All @@ -223,7 +232,10 @@ class AdsTracker extends Tracker {
this.sendData(data);
}

// Handle break ended event. Reset tracker to ignore events until new break.
/**
* Handle break ended event. Reset tracker to ignore events until new break.
* @param {cast.framework.events.EventType.BREAK_ENDED} event
*/
handleBreakEnded(event) {
let data = {};
data.id = this.breakId;
Expand All @@ -236,8 +248,8 @@ class AdsTracker extends Tracker {

/**
* Sends the event data to respective analytics agents.
* @param {cast.framework.events.BreaksEvent|
* cast.framework.events.BreaksEvent.MediaElementEvent} event
* @param {Object} data
* @override
*/
sendData(data) {
ga('send', 'event', this.type, data.action, data.id);
Expand All @@ -246,9 +258,9 @@ class AdsTracker extends Tracker {


/**
* Child of the tracker class used to profile the types of senders interacting
* with the receiver. Each sender type is mapped to its senderId through the
* regular expressions stored in this object.
* Tracker that handles profiling the types of senders interacting with the
* receiver. Each sender type is mapped to its senderId through the regular
* expressions stored in this object.
*/
class SenderTracker extends Tracker {
constructor() {
Expand All @@ -273,8 +285,17 @@ class SenderTracker extends Tracker {
}
}

/**
* Handles the incoming registered event for sender requests and sender
* connected events. Each unique sender id is added as a key to the tracker
* instance's sender property. The event data is sent when a senderId is
* registered for the first time.
* @param {cast.framework.events.category.REQUEST|
* cast.framework.system.EventType.SENDER_CONNECTED} event
* @override
*/
handleEvent(event) {
//Map the event senderId to its senderType if not already registered.
// Map the event senderId to its senderType if not already registered.
if (!this.senders[event.senderId]) {
this.senders[event.senderId] = this.getSenderType(event.senderId);
let data = {};
Expand All @@ -286,7 +307,11 @@ class SenderTracker extends Tracker {
}
}

// Obtains the senderType based on the senderId REGEX defined in this.
/**
* Obtains the senderType based on the senderId REGEX defined in this class.
* @param {string} senderId The sender identifier to be categorized.
* @return {string} The sender type identified.
*/
getSenderType(senderId) {
let senderType = null;
Object.entries(this.SenderIdRegex).forEach(([currType, regex]) => {
Expand All @@ -298,16 +323,21 @@ class SenderTracker extends Tracker {
return senderType || "OTHER_SENDER";
}

/**
* Sends the event data to respective analytics agents.
* @param {Object} data
* @override
*/
sendData(data) {
ga('send', 'event', this.type, data.action, data.senderType);
}
}


/**
* Child of the tracker class. Used to determine if loaded content is suggested
* or selected by the user. Requires the loaded media to have customData with
* property isSuggested.
* Tracker that determines if the loaded content is suggested by the queue or
* selected by the user. Detection requires that the loaded media to have
* customData with the property isSuggested.
*/
class ContentTracker extends Tracker {
constructor() {
Expand All @@ -317,6 +347,12 @@ class ContentTracker extends Tracker {
];
}

/**
* Handles the registered event. Checks the customData of the media for its
* isSuggested property to determine if the content is suggested or not.
* @param {cast.framework.events.EventType.PLAYER_LOAD_COMPLETE} event
* @override
*/
handleEvent(event) {
let data = {};

Expand All @@ -335,6 +371,11 @@ class ContentTracker extends Tracker {
this.sendData(data);
}

/**
* Sends the event data to respective analytics agents.
* @param {Object} data
* @override
*/
sendData(data) {
ga('send', 'event', this.type, data.action, data.id);
}
Expand Down
15 changes: 9 additions & 6 deletions js/cast_event_types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Google LLC. All Rights Reserved.
/**
Copyright 2022 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,19 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

'use_strict';

/*
* Enumeration type for determining the dispatcher of each of the cast events
/**
* Enumeration type for determining the dispatcher of each of the cast events.
*/
const EventOwner = {
PLAYER_MANAGER: 1,
CAST_RECEIVER_CONTEXT: 2
}

/*
/**
* Map for all the supported event types in the CAF SDK to be used by the
* analytics modules. Note there is one overlapping event (ERROR) on both
* analytics modules. Note there is one overlapping event (ERROR) on both
* system and standard events. Look at the mapping located in the object.
* @enum {[cast.framework.events.EventType|cast.framework.system.EventType,
* EventOwner]}
*/
const CastEventType = {
ALL: {event: cast.framework.events.EventType.ALL, owner: EventOwner.PLAYER_MANAGER},
Expand Down
Loading

1 comment on commit d6a2fe0

@mnr54318950
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

css/receiver.css

Please sign in to comment.