@internetarchive/collection-browser 2.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/collection-browser.js +10 -7
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/utils/analytics-events.d.ts +1 -0
- package/dist/src/utils/analytics-events.js +1 -0
- package/dist/src/utils/analytics-events.js.map +1 -1
- package/dist/test/collection-browser.test.js +47 -1
- package/dist/test/collection-browser.test.js.map +1 -1
- package/package.json +1 -1
- package/src/collection-browser.ts +10 -7
- package/src/utils/analytics-events.ts +1 -0
- package/test/collection-browser.test.ts +67 -1
package/package.json
CHANGED
|
@@ -890,20 +890,23 @@ export class CollectionBrowser
|
|
|
890
890
|
* including the collapsible container (with header) and the facets themselves.
|
|
891
891
|
*/
|
|
892
892
|
private get mobileFacetsTemplate(): TemplateResult {
|
|
893
|
-
const toggleFacetsVisible = () => {
|
|
893
|
+
const toggleFacetsVisible = (e: Event) => {
|
|
894
894
|
this.isResizeToMobile = false;
|
|
895
895
|
this.mobileFacetsVisible = !this.mobileFacetsVisible;
|
|
896
|
+
|
|
897
|
+
const target = e.target as HTMLDetailsElement;
|
|
898
|
+
this.analyticsHandler?.sendEvent({
|
|
899
|
+
category: this.searchContext,
|
|
900
|
+
action: analyticsActions.mobileFacetsToggled,
|
|
901
|
+
label: target.open ? 'open' : 'closed',
|
|
902
|
+
});
|
|
896
903
|
};
|
|
897
904
|
|
|
898
905
|
return html`
|
|
899
|
-
<details
|
|
900
|
-
id="mobile-filter-collapse"
|
|
901
|
-
@click=${toggleFacetsVisible}
|
|
902
|
-
@keyup=${toggleFacetsVisible}
|
|
903
|
-
>
|
|
906
|
+
<details id="mobile-filter-collapse" @toggle=${toggleFacetsVisible}>
|
|
904
907
|
<summary>
|
|
905
908
|
<span class="collapser-icon">${chevronIcon}</span>
|
|
906
|
-
<h2
|
|
909
|
+
<h2>${msg('Filters')}</h2>
|
|
907
910
|
${this.clearFiltersBtnTemplate(true)}
|
|
908
911
|
</summary>
|
|
909
912
|
${this.facetsTemplate}
|
|
@@ -14,6 +14,7 @@ export enum analyticsActions {
|
|
|
14
14
|
facetDeselected = 'facetDeselected',
|
|
15
15
|
facetNegativeSelected = 'facetNegativeSelected',
|
|
16
16
|
facetNegativeDeselected = 'facetNegativeDeselected',
|
|
17
|
+
mobileFacetsToggled = 'mobileFacetsToggled',
|
|
17
18
|
partOfCollectionClicked = 'partOfCollectionClicked',
|
|
18
19
|
histogramChanged = 'histogramChanged',
|
|
19
20
|
histogramChangedFromModal = 'histogramChangedFromModal',
|
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
} from '../src/models';
|
|
16
16
|
import { MockSearchService } from './mocks/mock-search-service';
|
|
17
17
|
import { MockAnalyticsHandler } from './mocks/mock-analytics-handler';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
analyticsActions,
|
|
20
|
+
analyticsCategories,
|
|
21
|
+
} from '../src/utils/analytics-events';
|
|
19
22
|
import type { TileDispatcher } from '../src/tiles/tile-dispatcher';
|
|
20
23
|
import type { CollectionFacets } from '../src/collection-facets';
|
|
21
24
|
import type { EmptyPlaceholder } from '../src/empty-placeholder';
|
|
@@ -1227,6 +1230,69 @@ describe('Collection Browser', () => {
|
|
|
1227
1230
|
expect(mobileFacets).to.exist;
|
|
1228
1231
|
});
|
|
1229
1232
|
|
|
1233
|
+
it('fires analytics when mobile facets toggled', async () => {
|
|
1234
|
+
const searchService = new MockSearchService();
|
|
1235
|
+
const analyticsHandler = new MockAnalyticsHandler();
|
|
1236
|
+
const el = await fixture<CollectionBrowser>(
|
|
1237
|
+
html`<collection-browser
|
|
1238
|
+
.searchService=${searchService}
|
|
1239
|
+
.analyticsHandler=${analyticsHandler}
|
|
1240
|
+
.searchContext=${'foobar-context'}
|
|
1241
|
+
.mobileBreakpoint=${9999}
|
|
1242
|
+
></collection-browser>`
|
|
1243
|
+
);
|
|
1244
|
+
|
|
1245
|
+
el.baseQuery = 'collection:foo';
|
|
1246
|
+
await el.updateComplete;
|
|
1247
|
+
|
|
1248
|
+
const contentContainer = el.shadowRoot?.querySelector(
|
|
1249
|
+
'#content-container'
|
|
1250
|
+
) as HTMLElement;
|
|
1251
|
+
|
|
1252
|
+
el.handleResize({
|
|
1253
|
+
target: contentContainer,
|
|
1254
|
+
contentRect: contentContainer.getBoundingClientRect(),
|
|
1255
|
+
borderBoxSize: [],
|
|
1256
|
+
contentBoxSize: [],
|
|
1257
|
+
devicePixelContentBoxSize: [],
|
|
1258
|
+
});
|
|
1259
|
+
await el.updateComplete;
|
|
1260
|
+
|
|
1261
|
+
const mobileFacets = el.shadowRoot?.querySelector(
|
|
1262
|
+
'#mobile-filter-collapse'
|
|
1263
|
+
) as HTMLDetailsElement;
|
|
1264
|
+
expect(mobileFacets).to.exist;
|
|
1265
|
+
|
|
1266
|
+
// We set up a Promise to wait for the 'toggle' event on the collapser,
|
|
1267
|
+
// which is what triggers the analytics.
|
|
1268
|
+
let facetsToggled = new Promise(resolve => {
|
|
1269
|
+
mobileFacets.addEventListener('toggle', resolve);
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
// Open the mobile facets accordion & check analytics
|
|
1273
|
+
const mobileFacetsHeader = mobileFacets.querySelector('summary');
|
|
1274
|
+
expect(mobileFacetsHeader).to.exist;
|
|
1275
|
+
mobileFacetsHeader!.click();
|
|
1276
|
+
await facetsToggled;
|
|
1277
|
+
expect(analyticsHandler.callCategory).to.equal('foobar-context');
|
|
1278
|
+
expect(analyticsHandler.callAction).to.equal(
|
|
1279
|
+
analyticsActions.mobileFacetsToggled
|
|
1280
|
+
);
|
|
1281
|
+
expect(analyticsHandler.callLabel).to.equal('open');
|
|
1282
|
+
|
|
1283
|
+
// Close the mobile facets accordion & check analytics
|
|
1284
|
+
facetsToggled = new Promise(resolve => {
|
|
1285
|
+
mobileFacets.addEventListener('toggle', resolve);
|
|
1286
|
+
});
|
|
1287
|
+
mobileFacetsHeader!.click();
|
|
1288
|
+
await facetsToggled;
|
|
1289
|
+
expect(analyticsHandler.callCategory).to.equal('foobar-context');
|
|
1290
|
+
expect(analyticsHandler.callAction).to.equal(
|
|
1291
|
+
analyticsActions.mobileFacetsToggled
|
|
1292
|
+
);
|
|
1293
|
+
expect(analyticsHandler.callLabel).to.equal('closed');
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1230
1296
|
it('sets parent collections to prop when searching a collection', async () => {
|
|
1231
1297
|
const searchService = new MockSearchService();
|
|
1232
1298
|
const el = await fixture<CollectionBrowser>(
|