Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable multiple features in analytic tokens #553

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __TESTS__/unit/analytics/analytics.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/sdkAnalytics/getAnalyticsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sdkAnalytics/getSDKAnalyticsSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export function getSDKAnalyticsSignature(_trackedAnalytics?: Partial<ITrackedPro
const encodedSDKVersion = encodeVersion(analyticsOptions.sdkSemver);
const encodedTechVersion = encodeVersion(twoPartVersion);

const featureCode = analyticsOptions.feature;
const featuresCode = analyticsOptions.features;
const SDKCode = analyticsOptions.sdkCode;
const algoVersion = 'A'; // The algo version is determined here, it should not be an argument


return `${algoVersion}${SDKCode}${encodedSDKVersion}${encodedTechVersion}${featureCode}`;
return `${algoVersion}${SDKCode}${encodedSDKVersion}${encodedTechVersion}${featuresCode}`;
} catch (e) {
// Either SDK or Node versions were unparsable
return 'E';
Expand Down
2 changes: 1 addition & 1 deletion src/sdkAnalytics/interfaces/IAnalyticsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface IAnalyticsOptions {
sdkSemver: string,
techVersion: string,
sdkCode: string,
feature: string
features: string
}