Skip to content

Commit

Permalink
remove extra rtf analytics on results cards (#960)
Browse files Browse the repository at this point in the history
Prior to this change, rtf click analytics on links would fire twice.
This is due to both the SDK's base card component, and also the theme's
base card component, which is on top of the SDK's base card, both registering
click event handlers.

J=TECHOPS-2149
TEST=manual
  • Loading branch information
oshi97 authored Sep 28, 2021
1 parent f661c2e commit 7edda52
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions cards/card_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ BaseCard["{{componentName}}"] = class extends ANSWERS.Component {
})
);
}

const rtfElement = this._container.querySelector('.js-yxt-rtfValue');
if (rtfElement) {
const fieldName = rtfElement.dataset.fieldName;
rtfElement.addEventListener('click', e => this._handleRtfClickAnalytics(e, fieldName));
}
}

setState(data) {
Expand Down Expand Up @@ -94,38 +88,6 @@ BaseCard["{{componentName}}"] = class extends ANSWERS.Component {
);
}

/**
* A click handler for links in a Rich Text attriubte. When such a link is
* clicked, an {@link AnalyticsEvent} needs to be fired.
*
* @param {MouseEvent} event The click event.
* @param {string} fieldName The name of the Rich Text field used in the
* attriubte.
*/
_handleRtfClickAnalytics (event, fieldName) {
const ctaType = event.target.dataset.ctaType;
if (!ctaType) {
return;
}

const analyticsOptions = {
directAnswer: false,
verticalKey: this.verticalKey,
searcher: this._config.isUniversal ? 'UNIVERSAL' : 'VERTICAL',
entityId: this.result.id,
url: event.target.href
};
if (!fieldName) {
console.warn('Field name not provided for RTF click analytics');
} else {
analyticsOptions.fieldName = fieldName;
}

const analyticsEvent = new ANSWERS.AnalyticsEvent(ctaType);
analyticsEvent.addOptions(analyticsOptions);
this.analyticsReporter.report(analyticsEvent);
}

static get type() {
return `{{componentName}}`;
}
Expand Down

0 comments on commit 7edda52

Please sign in to comment.