Merge branch 'add-referrer-to-pageview-event-7.2' into add-referrer-to-pageview-event-7.4

This commit is contained in:
Art Lowel
2023-05-02 18:31:06 +02:00
37 changed files with 287 additions and 56 deletions

View File

@@ -0,0 +1,53 @@
import { of as observableOf } from 'rxjs';
import { RouteService } from './route.service';
import { BrowserReferrerService } from './browser.referrer.service';
describe(`BrowserReferrerService`, () => {
let service: BrowserReferrerService;
const documentReferrer = 'https://www.referrer.com';
const origin = 'https://www.dspace.org';
let routeService: RouteService;
beforeEach(() => {
routeService = {
getPreviousUrl: () => observableOf('')
} as any;
service = new BrowserReferrerService(
{ referrer: documentReferrer },
routeService,
{ getCurrentOrigin: () => origin } as any
);
});
describe(`getReferrer`, () => {
let prevUrl: string;
describe(`when getPreviousUrl is an empty string`, () => {
beforeEach(() => {
prevUrl = '';
spyOn(routeService, 'getPreviousUrl').and.returnValue(observableOf(prevUrl));
});
it(`should return document.referrer`, (done: DoneFn) => {
service.getReferrer().subscribe((emittedReferrer: string) => {
expect(emittedReferrer).toBe(documentReferrer);
done();
});
});
});
describe(`when getPreviousUrl is not empty`, () => {
beforeEach(() => {
prevUrl = '/some/local/route';
spyOn(routeService, 'getPreviousUrl').and.returnValue(observableOf(prevUrl));
});
it(`should return the value emitted by getPreviousUrl combined with the origin from HardRedirectService`, (done: DoneFn) => {
service.getReferrer().subscribe((emittedReferrer: string) => {
expect(emittedReferrer).toBe(origin + prevUrl);
done();
});
});
});
});
});

View File

@@ -0,0 +1,48 @@
import { ReferrerService } from './referrer.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { isEmpty } from '../../shared/empty.util';
import { URLCombiner } from '../url-combiner/url-combiner';
import { Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { HardRedirectService } from './hard-redirect.service';
import { RouteService } from './route.service';
/**
* A service to determine the referrer
*
* The browser implementation will get the referrer from document.referrer, in the event that the
* previous page visited was not an angular URL. If it was, the route history in the store must be
* used, since document.referrer doesn't get updated on route changes
*/
@Injectable()
export class BrowserReferrerService extends ReferrerService {
constructor(
@Inject(DOCUMENT) protected document: any,
protected routeService: RouteService,
protected hardRedirectService: HardRedirectService,
) {
super();
}
/**
* Return the referrer
*
* Return the referrer URL based on the route history in the store. If there is no route history
* in the store yet, document.referrer will be used
*/
public getReferrer(): Observable<string> {
return this.routeService.getPreviousUrl().pipe(
map((prevUrl: string) => {
// if we don't have anything in the history yet, return document.referrer
// (note that that may be empty too, e.g. if you've just opened a new browser tab)
if (isEmpty(prevUrl)) {
return this.document.referrer;
} else {
return new URLCombiner(this.hardRedirectService.getCurrentOrigin(), prevUrl).toString();
}
})
);
}
}

View File

@@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
/**
* A service to determine the referrer, i.e. the previous URL that led the user to the current one
*/
@Injectable()
export abstract class ReferrerService {
/**
* Return the referrer
*/
abstract getReferrer(): Observable<string>;
}

View File

@@ -0,0 +1,34 @@
import { ServerReferrerService } from './server.referrer.service';
describe(`ServerReferrerService`, () => {
let service: ServerReferrerService;
const referrer = 'https://www.referrer.com';
describe(`getReferrer`, () => {
describe(`when the referer header is set`, () => {
beforeEach(() => {
service = new ServerReferrerService({ headers: { referer: referrer }});
});
it(`should return the referer header`, (done: DoneFn) => {
service.getReferrer().subscribe((emittedReferrer: string) => {
expect(emittedReferrer).toBe(referrer);
done();
});
});
});
describe(`when the referer header is not set`, () => {
beforeEach(() => {
service = new ServerReferrerService({ headers: {}});
});
it(`should return an empty string`, (done: DoneFn) => {
service.getReferrer().subscribe((emittedReferrer: string) => {
expect(emittedReferrer).toBe('');
done();
});
});
});
});
});

View File

@@ -0,0 +1,31 @@
import { ReferrerService } from './referrer.service';
import { Observable, of as observableOf } from 'rxjs';
import { Inject, Injectable } from '@angular/core';
import { REQUEST } from '@nguniversal/express-engine/tokens';
/**
* A service to determine the referrer
*
* The server implementation will get the referrer from the 'Referer' header of the request sent to
* the express server
*/
@Injectable()
export class ServerReferrerService extends ReferrerService {
constructor(
@Inject(REQUEST) protected request: any,
) {
super();
}
/**
* Return the referrer
*
* Return the 'Referer' header from the request, or an empty string if the header wasn't set
* (for consistency with the document.referrer property on the browser side)
*/
public getReferrer(): Observable<string> {
const referrer = this.request.headers.referer || '';
return observableOf(referrer);
}
}

View File

@@ -5,7 +5,7 @@
</div> </div>
<a *ngIf="linkType != linkTypes.None" <a *ngIf="linkType != linkTypes.None"
[target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -36,7 +36,7 @@
</p> </p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -5,7 +5,7 @@
</div> </div>
<a *ngIf="linkType != linkTypes.None" <a *ngIf="linkType != linkTypes.None"
[target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -36,7 +36,7 @@
</p> </p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -5,7 +5,7 @@
</div> </div>
<a *ngIf="linkType != linkTypes.None" <a *ngIf="linkType != linkTypes.None"
[target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -40,7 +40,7 @@
</p> </p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"> [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true">
</ds-thumbnail> </ds-thumbnail>
@@ -15,7 +15,7 @@
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<ds-truncatable [id]="dso.id"> <ds-truncatable [id]="dso.id">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out" [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"
[innerHTML]="dsoTitle"></a> [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" <span *ngIf="linkType == linkTypes.None"

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"> [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true">
</ds-thumbnail> </ds-thumbnail>
@@ -15,7 +15,7 @@
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<ds-truncatable [id]="dso.id"> <ds-truncatable [id]="dso.id">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out" [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"
[innerHTML]="dsoTitle"></a> [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" <span *ngIf="linkType == linkTypes.None"

View File

@@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"> [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true">
</ds-thumbnail> </ds-thumbnail>
@@ -13,7 +13,7 @@
<div [ngClass]="showThumbnails ? 'col-9' : 'col-md-12'"> <div [ngClass]="showThumbnails ? 'col-9' : 'col-md-12'">
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<ds-truncatable [id]="dso.id"> <ds-truncatable [id]="dso.id">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out" [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"
[innerHTML]="dsoTitle"></a> [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" <span *ngIf="linkType == linkTypes.None"

View File

@@ -5,7 +5,7 @@
</div> </div>
<a *ngIf="linkType != linkTypes.None" <a *ngIf="linkType != linkTypes.None"
[target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -42,7 +42,7 @@
</p> </p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -5,7 +5,7 @@
</div> </div>
<a *ngIf="linkType != linkTypes.None" <a *ngIf="linkType != linkTypes.None"
[target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -35,7 +35,7 @@
</p> </p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -5,7 +5,7 @@
</div> </div>
<a *ngIf="linkType != linkTypes.None" <a *ngIf="linkType != linkTypes.None"
[target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -30,7 +30,7 @@
</p> </p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [routerLink]="[itemPageRoute]" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="dont-break-out"> [routerLink]="[itemPageRoute]" class="dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" <ds-thumbnail [thumbnail]="dso?.thumbnail | async"
[defaultImage]="'assets/images/orgunit-placeholder.svg'" [defaultImage]="'assets/images/orgunit-placeholder.svg'"
@@ -21,7 +21,7 @@
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<ds-truncatable [id]="dso.id"> <ds-truncatable [id]="dso.id">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead" [routerLink]="[itemPageRoute]" class="lead"
[innerHTML]="dsoTitle || ('orgunit.listelement.no-title' | translate)"></a> [innerHTML]="dsoTitle || ('orgunit.listelement.no-title' | translate)"></a>
<span *ngIf="linkType == linkTypes.None" <span *ngIf="linkType == linkTypes.None"

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="dont-break-out"> [routerLink]="[itemPageRoute]" class="dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" <ds-thumbnail [thumbnail]="dso?.thumbnail | async"
[defaultImage]="'assets/images/person-placeholder.svg'" [defaultImage]="'assets/images/person-placeholder.svg'"
@@ -21,7 +21,7 @@
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<ds-truncatable [id]="dso.id"> <ds-truncatable [id]="dso.id">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead" [routerLink]="[itemPageRoute]" class="lead"
[innerHTML]="dsoTitle || ('person.listelement.no-title' | translate)"></a> [innerHTML]="dsoTitle || ('person.listelement.no-title' | translate)"></a>
<span *ngIf="linkType == linkTypes.None" <span *ngIf="linkType == linkTypes.None"

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="dont-break-out"> [routerLink]="[itemPageRoute]" class="dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" <ds-thumbnail [thumbnail]="dso?.thumbnail | async"
[defaultImage]="'assets/images/project-placeholder.svg'" [defaultImage]="'assets/images/project-placeholder.svg'"
@@ -21,7 +21,7 @@
<ds-truncatable [id]="dso.id"> <ds-truncatable [id]="dso.id">
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out" [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"
[innerHTML]="dsoTitle"></a> [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" <span *ngIf="linkType == linkTypes.None"

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'"
rel="noopener noreferrer" class="dont-break-out"> [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" class="dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" <ds-thumbnail [thumbnail]="dso?.thumbnail | async"
[defaultImage]="'assets/images/person-placeholder.svg'" [defaultImage]="'assets/images/person-placeholder.svg'"
[alt]="'thumbnail.person.alt'" [alt]="'thumbnail.person.alt'"

View File

@@ -1,5 +1,5 @@
<div class="card"> <div class="card">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/collections/', object.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/collections/', object.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate">
<ds-thumbnail [thumbnail]="(object.logo | async)?.payload" [limitWidth]="false"> <ds-thumbnail [thumbnail]="(object.logo | async)?.payload" [limitWidth]="false">
</ds-thumbnail> </ds-thumbnail>
</a> </a>
@@ -11,7 +11,7 @@
<h4 class="card-title">{{object.name}}</h4> <h4 class="card-title">{{object.name}}</h4>
<p *ngIf="object.shortDescription" class="card-text">{{object.shortDescription}}</p> <p *ngIf="object.shortDescription" class="card-text">{{object.shortDescription}}</p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/collections/', object.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/collections/', object.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,5 +1,5 @@
<div class="card"> <div class="card">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/communities/', object.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/communities/', object.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate">
<ds-thumbnail [thumbnail]="(object.logo | async)?.payload" [limitWidth]="false"> <ds-thumbnail [thumbnail]="(object.logo | async)?.payload" [limitWidth]="false">
</ds-thumbnail> </ds-thumbnail>
</a> </a>
@@ -11,7 +11,7 @@
<h4 class="card-title">{{object.name}}</h4> <h4 class="card-title">{{object.name}}</h4>
<p *ngIf="object.shortDescription" class="card-text">{{object.shortDescription}}</p> <p *ngIf="object.shortDescription" class="card-text">{{object.shortDescription}}</p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/communities/', object.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/communities/', object.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,5 +1,5 @@
<div class="card"> <div class="card">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/collections/', dso.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/collections/', dso.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate">
<ds-thumbnail [thumbnail]="(dso.logo | async)?.payload" [limitWidth]="false"> <ds-thumbnail [thumbnail]="(dso.logo | async)?.payload" [limitWidth]="false">
</ds-thumbnail> </ds-thumbnail>
</a> </a>
@@ -12,7 +12,7 @@
<h4 class="card-title">{{dso.name}}</h4> <h4 class="card-title">{{dso.name}}</h4>
<p *ngIf="dso.shortDescription" class="card-text">{{dso.shortDescription}}</p> <p *ngIf="dso.shortDescription" class="card-text">{{dso.shortDescription}}</p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/collections/', dso.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/collections/', dso.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>
<ng-content></ng-content> <ng-content></ng-content>

View File

@@ -1,5 +1,5 @@
<div class="card"> <div class="card">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/communities/', dso.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/communities/', dso.id]" class="card-img-top" [attr.title]="'search.results.view-result' | translate">
<ds-thumbnail [thumbnail]="(dso.logo | async)?.payload" [limitWidth]="false"> <ds-thumbnail [thumbnail]="(dso.logo | async)?.payload" [limitWidth]="false">
</ds-thumbnail> </ds-thumbnail>
</a> </a>
@@ -12,7 +12,7 @@
<h4 class="card-title">{{dso.name}}</h4> <h4 class="card-title">{{dso.name}}</h4>
<p *ngIf="dso.shortDescription" class="card-text">{{dso.shortDescription}}</p> <p *ngIf="dso.shortDescription" class="card-text">{{dso.shortDescription}}</p>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/communities/', dso.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/communities/', dso.id]" class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>
<ng-content></ng-content> <ng-content></ng-content>

View File

@@ -2,7 +2,7 @@
<div class="position-absolute ml-1"> <div class="position-absolute ml-1">
<ng-content></ng-content> <ng-content></ng-content>
</div> </div>
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="[itemPageRoute]" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate"> class="card-img-top full-width" [attr.title]="'search.results.view-result' | translate">
<div> <div>
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="false">
@@ -37,7 +37,7 @@
</ds-truncatable-part> </ds-truncatable-part>
</ds-truncatable> </ds-truncatable>
<div *ngIf="linkType != linkTypes.None" class="text-center"> <div *ngIf="linkType != linkTypes.None" class="text-center">
<a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="[itemPageRoute]" <a [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[itemPageRoute]"
class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a> class="lead btn btn-primary viewButton">{{ 'search.results.view-result' | translate}}</a>
</div> </div>
</div> </div>

View File

@@ -1,5 +1,5 @@
<div class="d-flex flex-row"> <div class="d-flex flex-row">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="[]" [queryParams]="queryParams$ | async" [queryParamsHandling]="'merge'" class="lead"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="[]" [queryParams]="queryParams$ | async" [queryParamsHandling]="'merge'" class="lead">
{{object.value}} {{object.value}}
</a> </a>
<span *ngIf="linkType == linkTypes.None" class="lead"> <span *ngIf="linkType == linkTypes.None" class="lead">

View File

@@ -1,4 +1,4 @@
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/collections/' + object.id]" class="lead"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/collections/' + object.id]" class="lead">
{{object.name}} {{object.name}}
</a> </a>
<span *ngIf="linkType == linkTypes.None" class="lead"> <span *ngIf="linkType == linkTypes.None" class="lead">

View File

@@ -1,4 +1,4 @@
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/communities/' + object.id]" class="lead"> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/communities/' + object.id]" class="lead">
{{object.name}} {{object.name}}
</a> </a>
<span *ngIf="linkType == linkTypes.None" class="lead"> <span *ngIf="linkType == linkTypes.None" class="lead">

View File

@@ -2,7 +2,7 @@
<div *ngIf="showThumbnails" class="offset-3 offset-md-2 "></div> <div *ngIf="showThumbnails" class="offset-3 offset-md-2 "></div>
<div [ngClass]="showThumbnails ? 'col-9' : 'col-md-12'"> <div [ngClass]="showThumbnails ? 'col-9' : 'col-md-12'">
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/collections/' + dso.id]" class="lead" [innerHTML]="dsoTitle"></a> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/collections/' + dso.id]" class="lead" [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" class="lead" [innerHTML]="dsoTitle"></span> <span *ngIf="linkType == linkTypes.None" class="lead" [innerHTML]="dsoTitle"></span>
<div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="firstMetadataValue('dc.description.abstract')"></div> <div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="firstMetadataValue('dc.description.abstract')"></div>
</div> </div>

View File

@@ -2,7 +2,7 @@
<div *ngIf="showThumbnails" class="offset-md-2"></div> <div *ngIf="showThumbnails" class="offset-md-2"></div>
<div [ngClass]="showThumbnails ? 'col-9' : 'col-md-12'"> <div [ngClass]="showThumbnails ? 'col-9' : 'col-md-12'">
<ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge> <ds-type-badge *ngIf="showLabel" [object]="dso"></ds-type-badge>
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" [routerLink]="['/communities/' + dso.id]" class="lead" [innerHTML]="dsoTitle"></a> <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null" [routerLink]="['/communities/' + dso.id]" class="lead" [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" class="lead" [innerHTML]="dsoTitle"></span> <span *ngIf="linkType == linkTypes.None" class="lead" [innerHTML]="dsoTitle"></span>
<div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="firstMetadataValue('dc.description.abstract')"></div> <div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="firstMetadataValue('dc.description.abstract')"></div>
</div> </div>

View File

@@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div *ngIf="showThumbnails" class="col-3 col-md-2"> <div *ngIf="showThumbnails" class="col-3 col-md-2">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="dont-break-out"> [routerLink]="[itemPageRoute]" class="dont-break-out">
<ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true"> <ds-thumbnail [thumbnail]="dso?.thumbnail | async" [limitWidth]="true">
</ds-thumbnail> </ds-thumbnail>
@@ -17,7 +17,7 @@
</div> </div>
<ds-truncatable [id]="dso.id" *ngIf="object !== undefined && object !== null"> <ds-truncatable [id]="dso.id" *ngIf="object !== undefined && object !== null">
<a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" rel="noopener noreferrer" <a *ngIf="linkType != linkTypes.None" [target]="(linkType == linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType == linkTypes.ExternalLink) ? 'noopener' : null"
[routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out" [routerLink]="[itemPageRoute]" class="lead item-list-title dont-break-out"
[innerHTML]="dsoTitle"></a> [innerHTML]="dsoTitle"></a>
<span *ngIf="linkType == linkTypes.None" class="lead item-list-title dont-break-out" <span *ngIf="linkType == linkTypes.None" class="lead item-list-title dont-break-out"

View File

@@ -11,7 +11,10 @@ describe('Angulartics2DSpace', () => {
beforeEach(() => { beforeEach(() => {
angulartics2 = { angulartics2 = {
eventTrack: observableOf({action: 'pageView', properties: {object: 'mock-object'}}), eventTrack: observableOf({action: 'pageView', properties: {
object: 'mock-object',
referrer: 'https://www.referrer.com'
}}),
filterDeveloperMode: () => filter(() => true) filterDeveloperMode: () => filter(() => true)
} as any; } as any;
statisticsService = jasmine.createSpyObj('statisticsService', {trackViewEvent: null}); statisticsService = jasmine.createSpyObj('statisticsService', {trackViewEvent: null});
@@ -20,7 +23,7 @@ describe('Angulartics2DSpace', () => {
it('should use the statisticsService', () => { it('should use the statisticsService', () => {
provider.startTracking(); provider.startTracking();
expect(statisticsService.trackViewEvent).toHaveBeenCalledWith('mock-object' as any); expect(statisticsService.trackViewEvent).toHaveBeenCalledWith('mock-object' as any, 'https://www.referrer.com');
}); });
}); });

View File

@@ -25,7 +25,7 @@ export class Angulartics2DSpace {
private eventTrack(event) { private eventTrack(event) {
if (event.action === 'pageView') { if (event.action === 'pageView') {
this.statisticsService.trackViewEvent(event.properties.object); this.statisticsService.trackViewEvent(event.properties.object, event.properties.referrer);
} else if (event.action === 'search') { } else if (event.action === 'search') {
this.statisticsService.trackSearchEvent( this.statisticsService.trackSearchEvent(
event.properties.searchOptions, event.properties.searchOptions,

View File

@@ -1,6 +1,10 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import { Subscription } from 'rxjs/internal/Subscription';
import { take } from 'rxjs/operators';
import { hasValue } from '../../../shared/empty.util';
import { ReferrerService } from '../../../core/services/referrer.service';
/** /**
* This component triggers a page view statistic * This component triggers a page view statistic
@@ -10,18 +14,43 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model';
styleUrls: ['./view-tracker.component.scss'], styleUrls: ['./view-tracker.component.scss'],
templateUrl: './view-tracker.component.html', templateUrl: './view-tracker.component.html',
}) })
export class ViewTrackerComponent implements OnInit { export class ViewTrackerComponent implements OnInit, OnDestroy {
/**
* The DSpaceObject to track a view event about
*/
@Input() object: DSpaceObject; @Input() object: DSpaceObject;
/**
* The subscription on this.referrerService.getReferrer()
* @protected
*/
protected sub: Subscription;
constructor( constructor(
public angulartics2: Angulartics2 public angulartics2: Angulartics2,
public referrerService: ReferrerService
) { ) {
} }
ngOnInit(): void { ngOnInit(): void {
this.sub = this.referrerService.getReferrer()
.pipe(take(1))
.subscribe((referrer: string) => {
this.angulartics2.eventTrack.next({ this.angulartics2.eventTrack.next({
action: 'pageView', action: 'pageView',
properties: {object: this.object}, properties: {
object: this.object,
referrer
},
});
}); });
} }
ngOnDestroy(): void {
// unsubscribe in the case that this component is destroyed before
// this.referrerService.getReferrer() has emitted
if (hasValue(this.sub)) {
this.sub.unsubscribe();
}
}
} }

View File

@@ -26,12 +26,13 @@ describe('StatisticsService', () => {
it('should send a request to track an item view ', () => { it('should send a request to track an item view ', () => {
const mockItem: any = {uuid: 'mock-item-uuid', type: 'item'}; const mockItem: any = {uuid: 'mock-item-uuid', type: 'item'};
service.trackViewEvent(mockItem); service.trackViewEvent(mockItem, 'https://www.referrer.com');
const request: RestRequest = requestService.send.calls.mostRecent().args[0]; const request: RestRequest = requestService.send.calls.mostRecent().args[0];
expect(request.body).toBeDefined('request.body'); expect(request.body).toBeDefined('request.body');
const body = JSON.parse(request.body); const body = JSON.parse(request.body);
expect(body.targetId).toBe('mock-item-uuid'); expect(body.targetId).toBe('mock-item-uuid');
expect(body.targetType).toBe('item'); expect(body.targetType).toBe('item');
expect(body.referrer).toBe('https://www.referrer.com');
}); });
}); });

View File

@@ -31,11 +31,16 @@ export class StatisticsService {
/** /**
* To track a page view * To track a page view
* @param dso: The dso which was viewed * @param dso: The dso which was viewed
* @param referrer: The referrer used by the client to reach the dso page
*/ */
trackViewEvent(dso: DSpaceObject) { trackViewEvent(
dso: DSpaceObject,
referrer: string
) {
this.sendEvent('/statistics/viewevents', { this.sendEvent('/statistics/viewevents', {
targetId: dso.uuid, targetId: dso.uuid,
targetType: (dso as any).type targetType: (dso as any).type,
referrer
}); });
} }

View File

@@ -128,7 +128,7 @@
<div> <div>
{{ 'submission.sections.ccLicense.link' | translate }} {{ 'submission.sections.ccLicense.link' | translate }}
</div> </div>
<a class="license-link" href="{{ licenseLink }}" target="_blank" rel="noopener noreferrer"> <a class="license-link" href="{{ licenseLink }}" target="_blank" rel="noopener">
{{ licenseLink }} {{ licenseLink }}
</a> </a>
<div class="m-2"> <div class="m-2">

View File

@@ -31,6 +31,8 @@ import { GoogleAnalyticsService } from '../../app/statistics/google-analytics.se
import { AuthRequestService } from '../../app/core/auth/auth-request.service'; import { AuthRequestService } from '../../app/core/auth/auth-request.service';
import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service'; import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service';
import { BrowserInitService } from './browser-init.service'; import { BrowserInitService } from './browser-init.service';
import { ReferrerService } from '../../app/core/services/referrer.service';
import { BrowserReferrerService } from '../../app/core/services/browser.referrer.service';
export const REQ_KEY = makeStateKey<string>('req'); export const REQ_KEY = makeStateKey<string>('req');
@@ -107,6 +109,10 @@ export function getRequest(transferState: TransferState): any {
provide: AuthRequestService, provide: AuthRequestService,
useClass: BrowserAuthRequestService, useClass: BrowserAuthRequestService,
}, },
{
provide: ReferrerService,
useClass: BrowserReferrerService,
},
{ {
provide: LocationToken, provide: LocationToken,
useFactory: locationProvider, useFactory: locationProvider,

View File

@@ -29,6 +29,8 @@ import { Angulartics2Mock } from '../../app/shared/mocks/angulartics2.service.mo
import { AuthRequestService } from '../../app/core/auth/auth-request.service'; import { AuthRequestService } from '../../app/core/auth/auth-request.service';
import { ServerAuthRequestService } from '../../app/core/auth/server-auth-request.service'; import { ServerAuthRequestService } from '../../app/core/auth/server-auth-request.service';
import { ServerInitService } from './server-init.service'; import { ServerInitService } from './server-init.service';
import { ReferrerService } from '../../app/core/services/referrer.service';
import { ServerReferrerService } from '../../app/core/services/server.referrer.service';
export function createTranslateLoader(transferState: TransferState) { export function createTranslateLoader(transferState: TransferState) {
return new TranslateServerLoader(transferState, 'dist/server/assets/i18n/', '.json5'); return new TranslateServerLoader(transferState, 'dist/server/assets/i18n/', '.json5');
@@ -100,6 +102,10 @@ export function createTranslateLoader(transferState: TransferState) {
provide: HardRedirectService, provide: HardRedirectService,
useClass: ServerHardRedirectService, useClass: ServerHardRedirectService,
}, },
{
provide: ReferrerService,
useClass: ServerReferrerService,
},
] ]
}) })
export class ServerAppModule { export class ServerAppModule {