From c037207e78efbc5d52578ba09817444cb859d199 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Wed, 15 Mar 2023 15:12:06 +0200 Subject: [PATCH] enable multiple features in analytic tokens --- .../unit/analytics/analytics.node.test.ts | 18 ++++++++++++++++++ src/sdkAnalytics/getAnalyticsOptions.ts | 15 ++++++++++----- src/sdkAnalytics/getSDKAnalyticsSignature.ts | 4 ++-- .../interfaces/IAnalyticsOptions.ts | 2 +- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/__TESTS__/unit/analytics/analytics.node.test.ts b/__TESTS__/unit/analytics/analytics.node.test.ts index 28a7704c..c3b470c9 100644 --- a/__TESTS__/unit/analytics/analytics.node.test.ts +++ b/__TESTS__/unit/analytics/analytics.node.test.ts @@ -94,6 +94,24 @@ describe('Add analytics to a regular URL', () => { })).toContain('?_a=AZAlhAMB'); }); + it('Test lazyload, responsive & placeholder combined feature value', () => { + const cldImage = createNewImageWithAnalytics('sample'); + // AZ -> Algo A, SDK Code is Z + // Alh -> 1.24.0 from package.json + // AM -> 12.0.0 Underlying tech + // CAB -> lazyload, responsive & placeholder + expect(cldImage.toURL({ + trackedAnalytics: { + sdkCode: 'Z', + sdkSemver: '1.24.0', + techVersion: '12.0.0', + placeholder: true, + lazyload: true, + responsive: true, + } + })).toContain('?_a=AZAlhAMCAB'); + }); + it('Can be turned off', () => { const cldImage = createNewImageWithAnalytics('sample', {}, { analytics: false diff --git a/src/sdkAnalytics/getAnalyticsOptions.ts b/src/sdkAnalytics/getAnalyticsOptions.ts index 40fb2054..0ab01c0d 100644 --- a/src/sdkAnalytics/getAnalyticsOptions.ts +++ b/src/sdkAnalytics/getAnalyticsOptions.ts @@ -12,23 +12,28 @@ export function getAnalyticsOptions(options: ITrackedPropertiesThroughAnalytics) sdkSemver: options.sdkSemver, techVersion: options.techVersion, sdkCode: options.sdkCode, - feature: '0' + features: '0' }; + let features = ''; if (options.accessibility) { - analyticsOptions.feature = 'D'; + features += 'D'; } if (options.lazyload) { - analyticsOptions.feature = 'C'; + features += 'C'; } if (options.responsive) { - analyticsOptions.feature = 'A'; + features += 'A'; } if (options.placeholder) { - analyticsOptions.feature = 'B'; + features += 'B'; + } + + if (features) { + analyticsOptions.features = features; } return analyticsOptions; diff --git a/src/sdkAnalytics/getSDKAnalyticsSignature.ts b/src/sdkAnalytics/getSDKAnalyticsSignature.ts index a4a5094d..a31d33fd 100644 --- a/src/sdkAnalytics/getSDKAnalyticsSignature.ts +++ b/src/sdkAnalytics/getSDKAnalyticsSignature.ts @@ -69,12 +69,12 @@ export function getSDKAnalyticsSignature(_trackedAnalytics?: Partial