Skip to content

Commit ad0c21f

Browse files
author
strausr
committed
feat(analytics): add CLI feature detection for React SDK
1 parent d3def8e commit ad0c21f

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

packages/html/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type PictureSources = {minWidth?: number, maxWidth?: number, image: Cloud
2424

2525
export type PictureSource = {minWidth?: number, maxWidth?: number, image: CloudinaryImage, sizes?: string};
2626

27-
export type BaseAnalyticsOptions = {sdkSemver: string, techVersion: string, sdkCode: string};
27+
export type BaseAnalyticsOptions = {sdkSemver: string, techVersion: string, sdkCode: string, feature?: string};
2828

2929
export type AnalyticsOptions = Parameters<CloudinaryImage['toURL']>[0];
3030

packages/html/src/utils/analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const getAnalyticsOptions = (options?: BaseAnalyticsOptions, features: vo
66
sdkCode: options.sdkCode,
77
sdkSemver: options.sdkSemver,
88
techVersion: options.techVersion,
9+
...(options.feature !== undefined && { feature: options.feature }),
910
...features
1011
}
1112
} : null
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import React from 'react'
22

3+
// Detect if this project was created via create-cloudinary-react CLI
4+
function getCLIFeatureCode(): string {
5+
if (typeof process !== 'undefined' && process.env) {
6+
if (process.env.CLOUDINARY_SOURCE === 'cli' || process.env.CLD_CLI === 'true') {
7+
return 'B'; // CLI feature code
8+
}
9+
}
10+
return '0'; // Default (no specific feature)
11+
}
12+
13+
314
export const SDKAnalyticsConstants = {
415
sdkSemver: 'PACKAGE_VERSION_INJECTED_DURING_BUILD',
516
techVersion: React.version,
6-
sdkCode: 'J'
17+
sdkCode: 'J',
18+
feature: getCLIFeatureCode()
719
};

0 commit comments

Comments
 (0)