Skip to content

Commit

Permalink
feat: add internal analytics about new method & profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-roch committed Oct 14, 2024
1 parent b79f961 commit 742df46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { defaultProfiles } from './config/profiles';
import { isRawUrl } from './plugins/cloudinary/common';
import { unsigned_url_prefix } from '@cloudinary/url-gen/backwards/utils/unsigned_url_prefix';

const isDefaultProfile = (profile) => Object.keys(defaultProfiles).includes(profile);

export const getProfile = async (profile, initOptions) => {
if (Object.keys(defaultProfiles).includes(profile)) {
if (isDefaultProfile(profile)) {
return defaultProfiles[profile];
}

Expand All @@ -27,7 +29,12 @@ const player = async (elem, initOptions, ready) => {
const { profile, ...otherInitOptions } = initOptions;
try {
const profileOptions = profile ? await getProfile(profile, otherInitOptions) : {};
const options = Object.assign({}, profileOptions.playerOptions, otherInitOptions);
const options = Object.assign({}, profileOptions.playerOptions, otherInitOptions, {
_internalAnalyticsMetadata: {
newPlayerMethod: true,
profile: isDefaultProfile(profile) ? profile : !!profile,
},
});
const videoPlayer = new VideoPlayer(elem, options, ready);

const nativeVideoPlayerSourceMethod = videoPlayer.source;
Expand Down
5 changes: 4 additions & 1 deletion src/video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class VideoPlayer extends Utils.mixin(Eventable) {
this.videoElement = getResolveVideoElement(elem);

this.options = extractOptions(this.videoElement, initOptions);
console.log('1111', this.options);

this._videojsOptions = this.options.videojsOptions;

Expand Down Expand Up @@ -112,6 +113,7 @@ class VideoPlayer extends Utils.mixin(Eventable) {
return;
}
try {
const internalAnalyticsMetadata = this.options.videojsOptions._internalAnalyticsMetadata || {};
const analyticsData = getAnalyticsFromPlayerOptions(options);
const analyticsParams = new URLSearchParams(analyticsData).toString();
const baseParams = new URLSearchParams({
Expand All @@ -120,7 +122,8 @@ class VideoPlayer extends Utils.mixin(Eventable) {
// #if (process.env.WEBPACK_BUILD_LIGHT)
vpLightBuild: true,
// #endif
cloudName: options.cloudinary.cloudinaryConfig.cloud_name
cloudName: options.cloudinary.cloudinaryConfig.cloud_name,
...internalAnalyticsMetadata,
}).toString();
fetch(`${INTERNAL_ANALYTICS_URL}/video_player_source?${analyticsParams}&${baseParams}`);
} catch (e) {
Expand Down

0 comments on commit 742df46

Please sign in to comment.