Skip to content

Commit

Permalink
fix(FEC-8228): calculate correct referrer param for inline and iframe…
Browse files Browse the repository at this point in the history
… embeds (#123)

* acquire the referrer from the document.URL unless is an iframe then acquire it from document.referrer
* limit the referrer to 1K length
* pass the referrer to kanalytics plugin via config see kaltura/playkit-js-kanalytics#31
  • Loading branch information
yairans authored May 22, 2018
1 parent 461f7c6 commit 71401cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/common/plugins/plugins-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@flow
import pluginsConfig from './plugins-config.json'
import evaluate from '../utils/evaluate'
import {getReferrer} from '../utils/kaltura-params'
import {Utils} from 'playkit-js'

/**
Expand All @@ -21,7 +22,8 @@ function evaluatePluginsConfig(options: KalturaPlayerOptionsObject): void {
sessionId: options.session.id,
ks: options.session.ks,
uiConfId: options.session.uiConfId,
partnerId: options.session.partnerId
partnerId: options.session.partnerId,
referrer: getReferrer()
};
Object.keys(entryDataModel).forEach(key => {
if (entryDataModel[key] === undefined) {
Expand Down
3 changes: 2 additions & 1 deletion src/common/plugins/plugins-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"sessionId": "{{sessionId}}",
"ks": "{{ks}}",
"uiConfId": "{{uiConfId}}",
"partnerId": "{{partnerId}}"
"partnerId": "{{partnerId}}",
"referrer": "{{referrer}}"
},
"googleAnalytics": {
"entryId": "{{entryId}}",
Expand Down
19 changes: 17 additions & 2 deletions src/common/utils/kaltura-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ function updateSessionIdInUrl(source: Object = {}, sessionId: ?string): void {
}
}

/**
* @return {string} - The referrer
* @private
*/
function getReferrer(): string {
let referrer;
try {
referrer = window.parent.document.URL;
} catch (e) { // unfriendly iframe
referrer = document.referrer;
}
return referrer;
}

/**
* @param {PKMediaSourceObject} source - source
* @return {void}
Expand All @@ -83,7 +97,8 @@ function updateSessionIdInUrl(source: Object = {}, sessionId: ?string): void {
function addReferrer(source: PKMediaSourceObject): void {
if (source.url.indexOf(REFERRER) === -1) {
let delimiter = source.url.indexOf('?') === -1 ? '?' : '&';
source.url += delimiter + REFERRER + btoa(document.referrer || document.URL);
let referrer = btoa(getReferrer().substr(0, 1000));
source.url += delimiter + REFERRER + referrer;
}
}

Expand Down Expand Up @@ -123,4 +138,4 @@ function addKalturaParams(player: Player, playerConfig: PartialKalturaPlayerOpti
});
}

export {addKalturaParams, handleSessionId, updateSessionIdInUrl, addReferrer, addClientTag}
export {addKalturaParams, handleSessionId, updateSessionIdInUrl, getReferrer, addReferrer, addClientTag}

0 comments on commit 71401cc

Please sign in to comment.