Skip to content

Commit 6dae327

Browse files
authored
Add analyticsTags to trackConversion (#454)
1 parent 05a9799 commit 6dae327

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

spec/src/modules/tracker.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
40824082

40834083
expect(tracker.trackConversion(term, requiredParameters)).to.equal(true);
40844084
});
4085+
4086+
it('Should respond with a valid response when analyticsTags are provided', (done) => {
4087+
const { tracker } = new ConstructorIO({
4088+
apiKey: testApiKey,
4089+
fetch: fetchSpy,
4090+
...requestQueueOptions,
4091+
});
4092+
const parametersWithAnalyticsTags = {
4093+
...requiredParameters,
4094+
analyticsTags: testAnalyticsTag,
4095+
};
4096+
4097+
tracker.on('success', (responseParams) => {
4098+
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
4099+
4100+
// Request
4101+
expect(fetchSpy).to.have.been.called;
4102+
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag);
4103+
4104+
// Response
4105+
expect(responseParams).to.have.property('method').to.equal('POST');
4106+
expect(responseParams).to.have.property('message').to.equal('ok');
4107+
4108+
done();
4109+
});
4110+
4111+
expect(tracker.trackConversion(term, parametersWithAnalyticsTags)).to.equal(true);
4112+
});
40854113
});
40864114

40874115
describe('trackPurchase', () => {

src/modules/tracker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ class Tracker {
10281028
* @param {boolean} [parameters.isCustomType] - Specify if type is custom conversion type
10291029
* @param {string} [parameters.displayName] - Display name for the custom conversion type
10301030
* @param {string} [parameters.section="Products"] - Index section
1031+
* @param {object} [parameters.analyticsTags] - Pass additional analytics data
10311032
* @param {object} [networkParameters] - Parameters relevant to the network request
10321033
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
10331034
* @returns {(true|Error)}
@@ -1070,6 +1071,7 @@ class Tracker {
10701071
type,
10711072
is_custom_type,
10721073
isCustomType = is_custom_type,
1074+
analyticsTags,
10731075
} = parameters;
10741076

10751077
// Ensure support for both item_id and customer_id as parameters
@@ -1111,6 +1113,10 @@ class Tracker {
11111113
bodyParams.display_name = displayName;
11121114
}
11131115

1116+
if (analyticsTags) {
1117+
bodyParams.analytics_tags = analyticsTags;
1118+
}
1119+
11141120
const requestURL = `${requestPath}${applyParamsAsString(queryParams, this.options)}`;
11151121
const requestMethod = 'POST';
11161122
const requestBody = applyParams(bodyParams, { ...this.options, requestMethod });

src/types/tracker.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ declare class Tracker {
119119
displayName?: string;
120120
resultId?: string;
121121
section?: string;
122+
analyticsTags?: Record<string, string>;
122123
},
123124
networkParameters?: NetworkParameters
124125
): true | Error;

0 commit comments

Comments
 (0)