Skip to content

Commit

Permalink
handle converting sessionTrackingEnabled boolean in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Jaffee committed Nov 8, 2023
1 parent 09944a8 commit c86cd83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/convertStringToValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventPayload } from './EventPayload';

// Define the list of possibly numerical properties to check and convert
const propertiesToCheck = [
'sessionTrackingEnabled',
'versionNumber',
'siteUid',
'count',
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export function analyticsGTM(): Promise<string> {
const config = gtmPayload[0][1] as Record<string, unknown>;
const data = gtmPayload[1][1] as Record<string, unknown>;
if (config) {
const reporter = new AnalyticsEventReporter(config);
const correctedConfig = convertStringToValue(config);
const correctedData = convertStringToValue(data);
const reporter = new AnalyticsEventReporter(
correctedConfig as AnalyticsConfig
);
response = reporter.report(correctedData);
} else {
response = Promise.reject('No config found in payload.');
Expand Down
15 changes: 15 additions & 0 deletions tests/convertStringToValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ describe('convertTypesGTM Test', () => {
}
});
});
it('test convert AnayticsConfig - should convert sessionTrackingEnabled', () => {
const analyticsConfig = {
key: 'apiKey',
sessionTrackingEnabled: 'false',
region: 'US'
};

const result = convertStringToValue(analyticsConfig);

expect(result).toEqual({
key: 'apiKey',
sessionTrackingEnabled: false,
region: 'US'
});
});
});

0 comments on commit c86cd83

Please sign in to comment.