Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/core/shared/search/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { PaginationService } from '../../pagination/pagination.service';
import { SearchConfigurationService } from './search-configuration.service';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { RequestEntry } from '../../data/request-entry.model';
import { Angulartics2 } from 'angulartics2';

@Component({ template: '' })
class DummyComponent {
Expand Down Expand Up @@ -57,6 +58,7 @@ describe('SearchService', () => {
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: PaginationService, useValue: {} },
{ provide: SearchConfigurationService, useValue: searchConfigService },
{ provide: Angulartics2, useValue: {} },
SearchService
],
});
Expand Down Expand Up @@ -124,6 +126,7 @@ describe('SearchService', () => {
{ provide: DSpaceObjectDataService, useValue: {} },
{ provide: PaginationService, useValue: paginationService },
{ provide: SearchConfigurationService, useValue: searchConfigService },
{ provide: Angulartics2, useValue: {} },
SearchService
],
});
Expand Down
33 changes: 33 additions & 0 deletions src/app/core/shared/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { SearchConfigurationService } from './search-configuration.service';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
import { RestRequest } from '../../data/rest-request.model';
import { BaseDataService } from '../../data/base/base-data.service';
import { Angulartics2 } from 'angulartics2';

/**
* A limited data service implementation for the 'discover' endpoint
Expand Down Expand Up @@ -96,6 +97,7 @@ export class SearchService implements OnDestroy {
private dspaceObjectService: DSpaceObjectDataService,
private paginationService: PaginationService,
private searchConfigurationService: SearchConfigurationService,
private angulartics2: Angulartics2,
) {
this.searchDataService = new SearchDataService();
}
Expand Down Expand Up @@ -320,6 +322,37 @@ export class SearchService implements OnDestroy {
});
}

/**
* Send search event to rest api using angularitics
* @param config Paginated search options used
* @param searchQueryResponse The response objects of the performed search
*/
trackSearch(config: PaginatedSearchOptions, searchQueryResponse: SearchObjects<DSpaceObject>) {
const filters: { filter: string, operator: string, value: string, label: string; }[] = [];
const appliedFilters = searchQueryResponse.appliedFilters || [];
for (let i = 0, filtersLength = appliedFilters.length; i < filtersLength; i++) {
const appliedFilter = appliedFilters[i];
filters.push(appliedFilter);
}
this.angulartics2.eventTrack.next({
action: 'search',
properties: {
searchOptions: config,
page: {
size: config.pagination.size, // same as searchQueryResponse.page.elementsPerPage
totalElements: searchQueryResponse.pageInfo.totalElements,
totalPages: searchQueryResponse.pageInfo.totalPages,
number: config.pagination.currentPage, // same as searchQueryResponse.page.currentPage
},
sort: {
by: config.sort.field,
order: config.sort.direction
},
filters: filters,
},
});
}

/**
* @returns {string} The base path to the search page
*/
Expand Down
3 changes: 1 addition & 2 deletions src/app/search-page/search-page.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<ds-themed-search></ds-themed-search>
<ds-search-tracker></ds-search-tracker>
<ds-themed-search [trackStatistics]="true"></ds-themed-search>
14 changes: 12 additions & 2 deletions src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ export class SearchComponent implements OnInit {
*/
@Input() showScopeSelector = true;

/**
* Whether or not to track search statistics by sending updates to the rest api
*/
@Input() trackStatistics = false;

/**
* The current configuration used during the search
*/
Expand Down Expand Up @@ -360,8 +365,13 @@ export class SearchComponent implements OnInit {
followLink<Item>('accessStatus', { isOptional: true, shouldEmbed: environment.item.showAccessStatuses })
).pipe(getFirstCompletedRemoteData())
.subscribe((results: RemoteData<SearchObjects<DSpaceObject>>) => {
if (results.hasSucceeded && results.payload?.page?.length > 0) {
this.resultFound.emit(results.payload);
if (results.hasSucceeded) {
if (this.trackStatistics) {
this.service.trackSearch(searchOptions, results.payload);
}
if (results.payload?.page?.length > 0) {
this.resultFound.emit(results.payload);
}
}
this.resultsRD$.next(results);
});
Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/search/themed-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ListableObject } from '../object-collection/shared/listable-object.mode
templateUrl: '../theme-support/themed.component.html',
})
export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'useCachedVersionIfAvailable', 'inPlaceSearch', 'linkType', 'paginationId', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showSidebar', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'resultFound', 'deselectObject', 'selectObject'];
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'useCachedVersionIfAvailable', 'inPlaceSearch', 'linkType', 'paginationId', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showSidebar', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'resultFound', 'deselectObject', 'selectObject', 'trackStatistics'];

@Input() configurationList: SearchConfigurationOption[] = [];

Expand Down Expand Up @@ -57,6 +57,8 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {

@Input() showScopeSelector = true;

@Input() trackStatistics = false;

@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter<SearchObjects<DSpaceObject>>();

@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
Expand Down