Skip to content

Commit

Permalink
[CSL 2968] add analytics tags support (#177)
Browse files Browse the repository at this point in the history
* Add analyticsTags

* Add test

* Add tests
  • Loading branch information
crgee1 authored Nov 16, 2023
1 parent 03e8185 commit 45214f2
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 0 deletions.
217 changes: 217 additions & 0 deletions spec/src/modules/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.equal('ok');

done();
});

expect(tracker.trackItemDetailLoad(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when required and optional parameters are provided', (done) => {
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
Expand Down Expand Up @@ -3827,6 +3854,34 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message').to.equal('ok');

done();
});

expect(tracker.trackConversion(
term,
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down Expand Up @@ -4503,6 +4558,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message');

done();
});

expect(tracker.trackPurchase(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down Expand Up @@ -5035,6 +5117,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message');

done();
});

expect(tracker.trackRecommendationView(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down Expand Up @@ -5517,6 +5626,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message');

done();
});

expect(tracker.trackRecommendationClick(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down Expand Up @@ -6017,6 +6153,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message');

done();
});

expect(tracker.trackBrowseResultsLoaded(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down Expand Up @@ -6536,6 +6699,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message');

done();
});

expect(tracker.trackBrowseResultClick(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down Expand Up @@ -7033,6 +7223,33 @@ describe('ConstructorIO - Tracker', () => {
})).to.equal(true);
});

it('Should respond with a valid response when required parameters and analyticsTags are provided', (done) => {
const analyticsTags = { foo: 'bar' };
const { tracker } = new ConstructorIO({
apiKey: testApiKey,
fetch: fetchSpy,
});

tracker.on('success', (responseParams) => {
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);

// Request
expect(fetchSpy).to.have.been.called;
expect(requestParams).to.have.property('analytics_tags').to.deep.equal(analyticsTags);

// Response
expect(responseParams).to.have.property('method').to.equal('POST');
expect(responseParams).to.have.property('message');

done();
});

expect(tracker.trackGenericResultClick(
{ analyticsTags, ...requiredParameters },
{ ...userParameters },
)).to.equal(true);
});

it('Should respond with a valid response when term, required parameters and origin referrer are provided', (done) => {
const originReferrer = 'https://localhost';
const { tracker } = new ConstructorIO({
Expand Down
Loading

0 comments on commit 45214f2

Please sign in to comment.