Skip to content

Commit

Permalink
Merge 4daeacc into 5d4a967
Browse files Browse the repository at this point in the history
  • Loading branch information
yen-tt authored Sep 2, 2022
2 parents 5d4a967 + 4daeacc commit 14dea71
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/answers-search-ui",
"version": "1.12.3",
"version": "1.12.4",
"description": "Javascript Answers Programming Interface",
"main": "dist/answers-umd.js",
"repository": {
Expand Down
7 changes: 4 additions & 3 deletions src/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @module AnalyticsReporter */

import AnalyticsEvent from './analyticsevent';
import { AnswersAnalyticsError } from '../errors/errors';
import { PRODUCTION } from '../constants';
import HttpRequester from '../http/httprequester';
import { getAnalyticsUrl } from '../utils/urlutils';
Expand Down Expand Up @@ -109,11 +108,13 @@ export default class AnalyticsReporter {
ytag('optin', true);
cookieData = ytag('yfpc', null);
} else if (this._conversionTrackingEnabled) {
throw new AnswersAnalyticsError('Tried to enable conversion tracking without including ytag');
console.error('Tried to enable conversion tracking without including ytag');
return false;
}

if (!(event instanceof AnalyticsEvent)) {
throw new AnswersAnalyticsError('Tried to send invalid analytics event', event);
console.error('Tried to send invalid analytics event', event);
return false;
}

if (includeQueryId) {
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/acceptancesuites/facetsonload.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test('Facets work with back/forward navigation and page refresh', async t => {
await options.toggleOption('Client Delivery');
currentFacets = await getFacetsFromRequest();
const state1 = {
c_cellPhone: [],
c_puppyPreference: [],
c_employeeDepartment: [{ c_employeeDepartment: { $eq: 'Client Delivery [SO]' } }],
languages: [],
Expand Down
20 changes: 11 additions & 9 deletions tests/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import AnalyticsReporter from '../../../src/core/analytics/analyticsreporter';
import HttpRequester from '../../../src/core/http/httprequester';
import { AnswersAnalyticsError } from '../../../src/core/errors/errors';
import AnalyticsEvent from '../../../src/core/analytics/analyticsevent';
import { getAnalyticsUrl } from '../../../src/core/utils/urlutils';
import { PRODUCTION } from '../../../src/core/constants';
Expand All @@ -21,10 +20,13 @@ describe('reporting events', () => {
analyticsReporter = new AnalyticsReporter('abc123', null, '213412', true);
});

it('throws an error if given a non-AnalyticsEvent', () => {
expect(() => {
analyticsReporter.report({ event_type: 'fake event' });
}).toThrow(AnswersAnalyticsError);
it('logs a console error if given a non-AnalyticsEvent', () => {
const consoleErrorSpy = jest.spyOn(console, 'error');
expect(analyticsReporter.report({ event_type: 'fake event' })).toBeFalsy();
expect(consoleErrorSpy).toHaveBeenLastCalledWith(
'Tried to send invalid analytics event',
{ event_type: 'fake event' }
);
});

it('sends the event via beacon in the "data" property', () => {
Expand Down Expand Up @@ -68,11 +70,11 @@ describe('reporting events', () => {
expect.anything());
});

it('throws error if opted in and ytag missing', () => {
it('logs a console error if opted in and ytag missing', () => {
analyticsReporter.setConversionTrackingEnabled(true);
expect(() => {
analyticsReporter.report(new AnalyticsEvent('thumbs_up'));
}).toThrow(AnswersAnalyticsError);
const consoleErrorSpy = jest.spyOn(console, 'error');
expect(analyticsReporter.report(new AnalyticsEvent('thumbs_up'))).toBeFalsy();
expect(consoleErrorSpy).toHaveBeenLastCalledWith('Tried to enable conversion tracking without including ytag');
});

it('includes cookies if opted in and ytag present', () => {
Expand Down

0 comments on commit 14dea71

Please sign in to comment.