From a1c8c1eb4ffd8362ce4cc7ab5ed47276cc5651ee Mon Sep 17 00:00:00 2001 From: jakub-roch <70572646+jakub-roch@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:27:29 +0200 Subject: [PATCH] feat: add internal analytics about new method & profiles (#699) * feat: add internal analytics about new method & profiles --- src/player.js | 11 +++++++++-- src/video-player.const.js | 1 + src/video-player.js | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/player.js b/src/player.js index 12967c77..60a2f905 100644 --- a/src/player.js +++ b/src/player.js @@ -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]; } @@ -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; diff --git a/src/video-player.const.js b/src/video-player.const.js index afad6d0d..c35c3292 100644 --- a/src/video-player.const.js +++ b/src/video-player.const.js @@ -12,6 +12,7 @@ export const CLOUDINARY_PARAMS = [ ]; export const PLAYER_PARAMS = CLOUDINARY_PARAMS.concat([ + '_internalAnalyticsMetadata', 'debug', 'publicId', 'source', diff --git a/src/video-player.js b/src/video-player.js index f3db2d7a..c1597415 100644 --- a/src/video-player.js +++ b/src/video-player.js @@ -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({ @@ -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) {