From 3752cc38f8a94e38cf4e6a543c399022b846b36b Mon Sep 17 00:00:00 2001 From: Tom Meyer Date: Mon, 12 Dec 2022 10:33:10 -0500 Subject: [PATCH 1/2] Gracefully handle Conversion Tracking failures. (#1796) This PR makes it such that if Conversion Tracking is enabled and the call to `ytag` fails, an `AnalyticsEvent` is still sent. We simply leave out any `cookieData`. This was done in response to the `ytag` asset being commonly blocked by various Ad-Blockers. TEST=auto Updated unit tests. --- src/core/analytics/analyticsreporter.js | 3 +-- tests/core/analytics/analyticsreporter.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/analytics/analyticsreporter.js b/src/core/analytics/analyticsreporter.js index bbac76ae6..d69cc96c7 100644 --- a/src/core/analytics/analyticsreporter.js +++ b/src/core/analytics/analyticsreporter.js @@ -108,8 +108,7 @@ export default class AnalyticsReporter { ytag('optin', true); cookieData = ytag('yfpc', null); } else if (this._conversionTrackingEnabled) { - console.error('Tried to enable conversion tracking without including ytag'); - return false; + console.error('Conversion Tracking is enabled without supplying ytag. Analytics event sent without Conversion Tracking info.'); } if (!(event instanceof AnalyticsEvent)) { diff --git a/tests/core/analytics/analyticsreporter.js b/tests/core/analytics/analyticsreporter.js index 73ebdd2a4..9b4be6ea9 100644 --- a/tests/core/analytics/analyticsreporter.js +++ b/tests/core/analytics/analyticsreporter.js @@ -73,8 +73,8 @@ describe('reporting events', () => { it('logs a console error if opted in and ytag missing', () => { analyticsReporter.setConversionTrackingEnabled(true); 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'); + expect(analyticsReporter.report(new AnalyticsEvent('thumbs_up'))).toBeTruthy(); + expect(consoleErrorSpy).toHaveBeenLastCalledWith('Conversion Tracking is enabled without supplying ytag. Analytics event sent without Conversion Tracking info.'); }); it('includes cookies if opted in and ytag present', () => { From 28324a9ae2063ef8235eecba96334cf8900bbb82 Mon Sep 17 00:00:00 2001 From: Tom Meyer Date: Mon, 12 Dec 2022 10:37:03 -0500 Subject: [PATCH 2/2] Update version to v1.15.2. --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 291047532..c6b81a3f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/answers-search-ui", - "version": "1.15.1", + "version": "1.15.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@yext/answers-search-ui", - "version": "1.15.1", + "version": "1.15.2", "license": "BSD-3-Clause", "dependencies": { "@mapbox/mapbox-gl-language": "^0.10.1", diff --git a/package.json b/package.json index c5d465885..1299dfd58 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/answers-search-ui", - "version": "1.15.1", + "version": "1.15.2", "description": "Javascript Search Programming Interface", "main": "dist/answers-umd.js", "repository": {