Skip to content

Commit

Permalink
feat: add internal analytics about new method & profiles (#699)
Browse files Browse the repository at this point in the history
* feat: add internal analytics about new method & profiles
  • Loading branch information
jakub-roch authored Oct 18, 2024
1 parent b79f961 commit a1c8c1e
Show file tree
Hide file tree
Showing 3 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
1 change: 1 addition & 0 deletions src/video-player.const.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const CLOUDINARY_PARAMS = [
];

export const PLAYER_PARAMS = CLOUDINARY_PARAMS.concat([
'_internalAnalyticsMetadata',
'debug',
'publicId',
'source',
Expand Down
4 changes: 3 additions & 1 deletion src/video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class VideoPlayer extends Utils.mixin(Eventable) {
return;
}
try {
const internalAnalyticsMetadata = options._internalAnalyticsMetadata ?? {};
const analyticsData = getAnalyticsFromPlayerOptions(options);
const analyticsParams = new URLSearchParams(analyticsData).toString();
const baseParams = new URLSearchParams({
Expand All @@ -120,7 +121,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 a1c8c1e

Please sign in to comment.