Skip to content

Commit

Permalink
Gracefully handle Conversion Tracking failures. (#1796)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmeyer2115 committed Dec 12, 2022
1 parent 530f4bd commit 3752cc3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3752cc3

Please sign in to comment.