Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Types mapped and customRecordEvent Implemented #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
427 changes: 421 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"babel-loader": "^9.1.3",
"chai": "^4.3.4",
"diff": "^5.0.0",
"jsdom": "^25.0.1",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"sinon": "^2.4.1",
Expand Down
68 changes: 36 additions & 32 deletions samples/sample2.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
<!DOCTYPE html>
<html>

<head>
<!-- newrelic video core -->
<script src="../dist/newrelic-video-core.min.js"></script>
</head>

<body>
<video id="myPlayer" controls height="315" width="560">
<source src="http://dl5.webmfiles.org/big-buck-bunny_trailer.webm" type='video/mp4'>
</video>
<head>
<script src="./agent.js"></script>
<!-- newrelic video core -->
<script src="../dist/newrelic-video-core.min.js"></script>
</head>

<body>
<video id="myPlayer" controls height="315" width="560">
<source
src="https://dl11.webmfiles.org/big-buck-bunny_trailer.webm"
type="video/webm"
/>
</video>
<script>

// A toy video tracker
class MyTracker extends nrvideo.VideoTracker {
getTrackerName() {
return "MyTracker"
return "MyTracker";
}

getRenditionWidth () {
return this.player.width
getRenditionWidth() {
return this.player.width;
}

getRenditionHeight () {
return this.player.height
getRenditionHeight() {
return this.player.height;
}

getSrc () {
return this.player.getElementsByTagName('source')[0].src
getSrc() {
return this.player.getElementsByTagName("source")[0].src;
}
}

// Set up a custom backend for event recording, it will be used instead of New Relic Browser Agent
let backend = new nrvideo.NRInsightsBackend("ACCOUNT ID", "API KEY")
// let backend = new nrvideo.NRInsightsBackend("ACCOUNT ID", "API KEY");

// Set a custom attribute
backend.setAttribute("videoElementId", "myPlayer")
nrvideo.Core.setBackend(backend)
// backend.setAttribute("videoElementId", "myPlayer");
// nrvideo.Core.setBackend(backend);

// Init tracker
nrvideo.Log.level = nrvideo.Log.Levels.ALL
var myPlayer = document.getElementById('myPlayer')
let myTracker = new MyTracker(myPlayer)
nrvideo.Core.addTracker(myTracker)
nrvideo.Log.level = nrvideo.Log.Levels.ALL;
var myPlayer = document.getElementById("myPlayer");
let myTracker = new MyTracker(myPlayer);
nrvideo.Core.addTracker(myTracker);

// Send a sample events
myTracker.send('SAMPLE_ACTION', { "num": 1})
myTracker.send('SAMPLE_ACTION', { "num": 2})
myTracker.send('SAMPLE_ACTION', { "num": 3})
myTracker.send('SAMPLE_ACTION', { "num": 4})
myTracker.sendVideoAction("VIDEO_SAMPLE_ACTION", { num: 1 });
myTracker.sendVideoAdAction("VIDEO_AD_SAMPLE_ACTION", { num: 2 });
myTracker.sendVideoErrorAction("VIDEO_ERROR_ACTION", { num: 3 });
myTracker.sendVideoCustomAction("VIDEO_CUSTOM_ACTION", { num: 4 });
//myTracker.state._isAd = true;
// myTracker.sendError({ errorCode: 404, errorName: "Ad Not Found!" });
</script>
</body>

</html>
</body>
</html>
65 changes: 33 additions & 32 deletions src/backend.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
/**
* Backend class provides the basic logic to create event backends.
* This class is intended to be subclassed, not directly used.
*
*
* @class Backend
*/
class Backend {

constructor() {
/**
* Custom attributes
* @private
*/
this._attributes = {}
}

constructor(eventType) {
/**
* Sends given event (to be overwritten by a subclass).
* @param {String} event Event to send.
* @param {Object} data Data associated to the event.
* Custom attributes
* @private
*/
send(event, data) {
data = Object.assign(data || {}, this._attributes)
}

/**
* Store custom attribute.
* @param {String} key Attribute name.
* @param {Object} value Attribute value.
*/
setAttribute(key, value) {
this._attributes[key] = value
}
this._attributes = {};
// this._eventType = eventType;
}

/**
* Store custom attribute list.
* @param {Object} attr Attributes.
*/
setAttributes(attr) {
this._attributes.append(attr)
}
/**
* Sends given event (to be overwritten by a subclass).
* @param {String} event Event to send.
* @param {Object} data Data associated to the event.
*/
send(event, data) {
data = Object.assign(data || {}, this._attributes);
}

/**
* Store custom attribute.
* @param {String} key Attribute name.
* @param {Object} value Attribute value.
*/
setAttribute(key, value) {
this._attributes[key] = value;
}

/**
* Store custom attribute list.
* @param {Object} attr Attributes.
*/
setAttributes(attr) {
this._attributes.append(attr);
}
}

export default Backend
export default Backend;
44 changes: 22 additions & 22 deletions src/chrono.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class Chrono {
/**
* Constructor
*/
constructor () {
this.reset()
constructor() {
this.reset();
}

/** Reset chrono values. */
reset () {
reset() {
/** Start time */
this.startTime = 0
this.startTime = 0;

/** Stop time */
this.stopTime = 0
this.stopTime = 0;

/**
* If you set an offset in a chrono, its value will be added getDeltaTime and stop.
Expand All @@ -29,50 +29,50 @@ class Chrono {
*
* @type {number}
*/
this.offset = 0
this.offset = 0;
}

/**
* Returns the time between start() and the last stop() in ms. Returns null if start wasn't
* called.
* @return {(number|null)} Time lapse in ms.
*/
getDeltaTime () {
getDeltaTime() {
if (this.startTime) {
return this.offset + (new Date().getTime() - this.startTime)
return this.offset + (new Date().getTime() - this.startTime);
} else {
return null
return null;
}
}

/**
* Starts the chrono.
*/
start () {
this.startTime = new Date().getTime()
this.stopTime = 0
start() {
this.startTime = new Date().getTime();
this.stopTime = 0;
}

/**
* Stops the timer and returns delta time.
* @return {(number|null)} Returns the delta time
*/
stop () {
this.stopTime = new Date().getTime()
return this.getDeltaTime()
stop() {
this.stopTime = new Date().getTime();
return this.getDeltaTime();
}

/**
* Creates a copy of the chrono.
* @returns {Chrono} Cloned chrono
*/
clone () {
var chrono = new Chrono()
chrono.startTime = this.startTime
chrono.stopTime = this.stopTime
chrono.offset = this.offset
return chrono
clone() {
var chrono = new Chrono();
chrono.startTime = this.startTime;
chrono.stopTime = this.stopTime;
chrono.offset = this.offset;
return chrono;
}
}

export default Chrono
export default Chrono;
Loading
Loading