Skip to content

Commit a6abed2

Browse files
committed
fix(VIDEO-20100): analytics improvements
1 parent 8c9fce2 commit a6abed2

File tree

7 files changed

+36
-13
lines changed

7 files changed

+36
-13
lines changed

src/components/title-bar/title-bar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'assets/styles/components/title-bar.scss';
33
import componentUtils from '../component-utils';
44
import { utf8ToBase64 } from '../../utils/utf8Base64';
55
import { getCloudinaryUrlPrefix } from 'plugins/cloudinary/common';
6+
import { appendQueryParams } from '../../utils/querystring';
67

78
// support VJS5 & VJS6 at the same time
89
const dom = videojs.dom || videojs;
@@ -47,7 +48,10 @@ class TitleBar extends Component {
4748

4849
const urlPrefix = getCloudinaryUrlPrefix(config);
4950
const deliveryType = source.getInitOptions().type || 'upload';
50-
const metadataUrl = `${urlPrefix}/_applet_/video_service/video_metadata/${deliveryType}/${utf8ToBase64(publicId)}.json`;
51+
const metadataUrl = appendQueryParams(
52+
`${urlPrefix}/_applet_/video_service/video_metadata/${deliveryType}/${utf8ToBase64(publicId)}.json`,
53+
source.queryParams()
54+
);
5155

5256
fetch(metadataUrl, {
5357
headers: {

src/plugins/chapters/chapters.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import videojs from 'video.js';
33
import './chapters.scss';
44
import { getCloudinaryUrlPrefix } from '../cloudinary/common';
55
import { utf8ToBase64 } from '../../utils/utf8Base64';
6+
import { appendQueryParams } from '../../utils/querystring';
67

78
/**
89
* Chapters plugin.
@@ -68,10 +69,11 @@ const ChaptersPlugin = (function () {
6869
return null;
6970
}
7071

71-
const { type: deliveryType } = this.player.cloudinary.source().resourceConfig();
72+
const source = this.player.cloudinary.source();
73+
const { type: deliveryType } = source.resourceConfig();
7274
const urlPrefix = getCloudinaryUrlPrefix(this.player.cloudinary.cloudinaryConfig());
7375
const fullUrl = `${urlPrefix}/_applet_/video_service/chapters/${deliveryType}/${utf8ToBase64(currentPublicId)}.vtt`;
74-
return `${fullUrl}?t=${Date.now()}`;
76+
return appendQueryParams(fullUrl, source.queryParams());
7577
};
7678

7779
/**

src/plugins/cloudinary/models/video-source/video-source.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class VideoSource extends BaseSource {
129129
}
130130

131131
options.cloudinaryConfig = options.cloudinaryConfig || this.cloudinaryConfig();
132-
133132
options.resource_type = this.resourceType() || options.resource_type;
133+
options.queryParams = this.queryParams();
134134

135135
if (publicId === true) {
136136
const urlPrefix = getCloudinaryUrlPrefix(options.cloudinaryConfig);
@@ -145,7 +145,8 @@ class VideoSource extends BaseSource {
145145
}
146146

147147
this._poster = new ImageSource(appletUrl, {
148-
cloudinaryConfig: options.cloudinaryConfig
148+
cloudinaryConfig: options.cloudinaryConfig,
149+
queryParams: options.queryParams
149150
});
150151

151152
return this;

src/plugins/text-tracks-manager/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getCloudinaryUrlPrefix } from '../cloudinary/common';
33
import { transcriptParser } from './parsers/transcriptParser';
44
import { srtParser } from './parsers/srtParser';
55
import { addTextTrackCues, fetchFileContent, refreshTextTrack, removeAllTextTrackCues } from './utils';
6+
import { appendQueryParams } from '../../utils/querystring';
67

78
const getTranscriptionFileUrl = (urlPrefix, deliveryType, publicId, languageCode = null) =>
89
`${urlPrefix}/_applet_/video_service/transcription/${deliveryType}/${languageCode ? `${languageCode}/` : ''}${utf8ToBase64(publicId)}.transcript`;
@@ -110,8 +111,9 @@ function textTracksManager() {
110111
const publicId = source.publicId();
111112
const deliveryType = source.resourceConfig().type;
112113
const urlPrefix = getCloudinaryUrlPrefix(player.cloudinary.cloudinaryConfig());
113-
const baseUrl = getTranscriptionFileUrl(urlPrefix, deliveryType, publicId);
114-
const localizedUrl = srclang ? getTranscriptionFileUrl(urlPrefix, deliveryType, publicId, srclang) : null;
114+
const queryParams = source.queryParams();
115+
const baseUrl = appendQueryParams(getTranscriptionFileUrl(urlPrefix, deliveryType, publicId), queryParams);
116+
const localizedUrl = srclang ? appendQueryParams(getTranscriptionFileUrl(urlPrefix, deliveryType, publicId, srclang), queryParams) : null;
115117

116118
return localizedUrl ? localizedUrl : baseUrl;
117119
};

src/utils/fetch-config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defaultProfiles } from 'cloudinary-video-player-profiles';
22
import { isRawUrl, getCloudinaryUrlPrefix } from '../plugins/cloudinary/common';
33
import { utf8ToBase64 } from '../utils/utf8Base64';
4+
import { appendQueryParams } from './querystring';
45

56
const isDefaultProfile = (profileName) => !!defaultProfiles.find(({ name }) => profileName === name);
67

@@ -15,21 +16,22 @@ const getDefaultProfileConfig = (profileName) => {
1516
};
1617

1718
const fetchConfig = async (options) => {
18-
const { profile, publicId, cloudinaryConfig, type = 'upload', videoConfig } = options;
19+
const { profile, publicId, cloudinaryConfig, type = 'upload', videoConfig, allowUsageReport = true } = options;
1920

2021
if (profile && isDefaultProfile(profile)) {
2122
return getDefaultProfileConfig(profile);
2223
}
2324

2425
const urlPrefix = getCloudinaryUrlPrefix(cloudinaryConfig) + '/_applet_/video_service';
26+
const queryParams = allowUsageReport ? { _s: `vp-${VERSION}` } : null;
2527

2628
let configUrl;
2729
if (profile) {
2830
configUrl = isRawUrl(profile)
2931
? profile
30-
: `${urlPrefix}/video_player_profiles/${profile.replaceAll(' ', '+')}.json`;
32+
: appendQueryParams(`${urlPrefix}/video_player_profiles/${profile.replaceAll(' ', '+')}.json`, queryParams);
3133
} else if (publicId && videoConfig !== false) {
32-
configUrl = `${urlPrefix}/video_player_config/video/${type}/${utf8ToBase64(publicId)}.json`;
34+
configUrl = appendQueryParams(`${urlPrefix}/video_player_config/video/${type}/${utf8ToBase64(publicId)}.json`, queryParams);
3335
} else {
3436
return {};
3537
}

src/utils/querystring.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ const objectToQuerystring = (obj) => {
99
return `?${query}`;
1010
};
1111

12-
export { objectToQuerystring };
12+
const appendQueryParams = (url, params) => {
13+
const queryString = objectToQuerystring(params);
14+
if (!queryString) {
15+
return url;
16+
}
17+
const separator = url.includes('?') ? '&' : '?';
18+
return `${url}${separator}${queryString.slice(1)}`;
19+
};
20+
21+
export { objectToQuerystring, appendQueryParams };

src/video-player.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { PLAYER_EVENT, SOURCE_TYPE } from './utils/consts';
2323
import { getAnalyticsFromPlayerOptions } from './utils/get-analytics-player-options';
2424
import { extendCloudinaryConfig, normalizeOptions, isRawUrl, ERROR_CODE } from './plugins/cloudinary/common';
2525
import { isVideoInReadyState, checkIfVideoIsAvailable } from './utils/video-retry';
26+
import { appendQueryParams } from './utils/querystring';
2627

2728
const INTERNAL_ANALYTICS_URL = 'https://analytics-api-s.cloudinary.com';
2829

@@ -265,9 +266,10 @@ class VideoPlayer extends Utils.mixin(Eventable) {
265266
transformation.flags = transformation.flags || [];
266267
transformation.flags.push('sprite');
267268

268-
const vttSrc = source.config()
269+
const vttUrl = source.config()
269270
.url(`${publicId}.vtt`, { transformation })
270271
.replace(/\.json$/, ''); // Handle playlist by tag
272+
const vttSrc = appendQueryParams(vttUrl, source.queryParams());
271273

272274
// vttThumbnails must be called differently on init and on source update.
273275
isFunction(this.videojs.vttThumbnails)
@@ -299,9 +301,10 @@ class VideoPlayer extends Utils.mixin(Eventable) {
299301
transformation.flags = transformation.flags || [];
300302
transformation.flags.push('getinfo');
301303

302-
const aiHighlightsGraphSrc = source.config()
304+
const aiHighlightsGraphUrl = source.config()
303305
.url(`${publicId}`, { transformation })
304306
.replace(/\.json$/, ''); // Handle playlist by tag
307+
const aiHighlightsGraphSrc = appendQueryParams(aiHighlightsGraphUrl, source.queryParams());
305308

306309
// Plugin is called differently on init and on source update.
307310
isFunction(this.videojs.aiHighlightsGraph)

0 commit comments

Comments
 (0)