Skip to content

Commit

Permalink
fix defaultInitialSearch (#1561)
Browse files Browse the repository at this point in the history
Prior to this change, if you didn't have a businessId, searches on page load
would error out because a search impression analytics event would try to be fired
using a null analytics reporter service.

J=SLAP-1616
TEST=manual,auto

I can run default initial searches, and searches using the query url param again, in my local
SDK test site and also the theme's test-site

tweaked the universalinitialsearch acceptance suite to not have a business id
  • Loading branch information
oshi97 committed Oct 4, 2021
1 parent 99fcbee commit bef0cc5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/answers-search-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ class AnswersSearchBar {
this._handlePonyfillCssVariables(parsedConfig.disableCssVariablesPonyfill)
.finally(() => {
this._onReady();
const impressionEvent = createImpressionEvent({
verticalKey: parsedConfig.search?.verticalKey,
standAlone: true
});
this._analyticsReporterService.report(impressionEvent, { includeQueryId: false });
if (this._analyticsReporterService) {
const impressionEvent = createImpressionEvent({
verticalKey: parsedConfig.search?.verticalKey,
standAlone: true
});
this._analyticsReporterService.report(impressionEvent, { includeQueryId: false });
}
});
}

Expand Down
11 changes: 6 additions & 5 deletions src/answers-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,19 @@ class Answers {
return asyncDeps.finally(() => {
this._onReady();

const isSearchBarActive = this.components.getActiveComponent(SearchComponent.type);
const numActiveComponents = this.components.getNumActiveComponents();

if (isSearchBarActive) {
const searchBarIsActive = !!this.components.getActiveComponent(SearchComponent.type);
if (searchBarIsActive && this._analyticsReporterService) {
const numActiveComponents = this.components.getNumActiveComponents();
const impressionEvent = createImpressionEvent({
verticalKey: parsedConfig.search?.verticalKey,
// check that 1 or 2 components are active because the
// search bar also creates the autocomplete component
standAlone: numActiveComponents >= 1 && numActiveComponents <= 2
});
this._analyticsReporterService.report(impressionEvent, { includeQueryId: false });
} else {
}

if (!searchBarIsActive) {
this._initQueryUpdateListener(parsedConfig.search);
}

Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/fixtures/html/universalinitialsearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
ANSWERS.init({
apiKey: 'df4b24f4075800e5e9705090c54c6c13',
experienceKey: 'sdkacceptancetests',
businessId: '3350634',
experienceVersion: 'PRODUCTION',
templateBundle: TemplateBundle.default,
search: {
Expand Down

0 comments on commit bef0cc5

Please sign in to comment.