Skip to content

Commit

Permalink
feat(FEC-9024): send beacon for non partner usage (#249)
Browse files Browse the repository at this point in the history
send usage beacon for usages of player without partner - this will be used to understand when player is configured incorrectly.
  • Loading branch information
OrenMe authored Jun 23, 2019
1 parent b2a57a7 commit d058e75
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/common/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import {configureExternalStreamRedirect} from './external-stream-redirect-helper
import {RemotePlayerManager} from '../cast/remote-player-manager';
import {RemoteControl} from '../cast/remote-control';
import {KalturaPlayer} from '../../kaltura-player';
import {addClientTag, addReferrer, updateSessionIdInUrl} from './kaltura-params';

const setupMessages: Array<Object> = [];
const CONTAINER_CLASS_NAME: string = 'kaltura-player-container';
const KALTURA_PLAYER_DEBUG_QS: string = 'debugKalturaPlayer';
const KAVA_DEFAULT_IMPRESSION =
'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0';

declare var __CONFIG_DOCS_URL__: string;

Expand Down Expand Up @@ -56,8 +59,16 @@ function validateTargetId(targetId: string): void {
* @returns {void}
*/
function validateProviderConfig(providerOptions: ProviderOptionsObject): void {
if (!providerOptions.partnerId && providerOptions.partnerId !== 0) {
throw new Error(ValidationErrorType.PARTNER_ID_REQUIRED);
if (!providerOptions.partnerId) {
//create source object as a 'hack' to be able to use utility functions on url
const source = {
url: KAVA_DEFAULT_IMPRESSION,
mimetype: ''
};
addReferrer(source);
addClientTag(source);
updateSessionIdInUrl(source, Utils.Generator.guid() + ':' + Utils.Generator.guid());
navigator.sendBeacon && navigator.sendBeacon(source.url);
}
}

Expand Down
19 changes: 11 additions & 8 deletions test/src/common/utils/setup-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ describe('error handling', function() {
}
});

it('should throw error because no partner id provided', function(done) {
it('should emit a beacon when no partner id provided', function(done) {
const div = document.createElement('DIV');
div.id = 'test-id';
document.body.appendChild(div);
try {
validateConfig({targetId: div.id, provider: {}});
} catch (e) {
document.body.removeChild(div);
e.message.should.equal(ValidationErrorType.PARTNER_ID_REQUIRED);
done();
}
sinon.spy(navigator, 'sendBeacon');
(navigator.sendBeacon.getCall(0) === null).should.be.true;
validateConfig({targetId: div.id, provider: {}});
document.body.removeChild(div);
navigator.sendBeacon
.getCall(0)
.args[0].should.include(
'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0&referrer'
);
done();
});
});

Expand Down

0 comments on commit d058e75

Please sign in to comment.