diff --git a/claims/claim-utils/displayClaims/displayClaims.component.ts b/claims/claim-utils/displayClaims/displayClaims.component.ts index 0f9b03ad..a5cc7f2f 100644 --- a/claims/claim-utils/displayClaims/displayClaims.component.ts +++ b/claims/claim-utils/displayClaims/displayClaims.component.ts @@ -111,7 +111,7 @@ export class DisplayClaimsComponent implements OnInit, OnDestroy { this.updateDescription(description); this.updateUrl(this.url); if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe()); } this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => { diff --git a/claims/linking/linkingGeneric.component.ts b/claims/linking/linkingGeneric.component.ts index 6e184a17..d1ff5637 100644 --- a/claims/linking/linkingGeneric.component.ts +++ b/claims/linking/linkingGeneric.component.ts @@ -75,7 +75,7 @@ export class LinkingGenericComponent { this.seoService.createLinkForCanonicalURL(this.url, false); if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ - this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe()); } this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => { diff --git a/deposit/depositFirstPage.component.ts b/deposit/depositFirstPage.component.ts index 7db06db4..3f88a03f 100644 --- a/deposit/depositFirstPage.component.ts +++ b/deposit/depositFirstPage.component.ts @@ -203,7 +203,7 @@ export class DepositFirstPageComponent { } if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ - this.subscriptions.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.title).subscribe()); } this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: null}); } diff --git a/error/isRouteEnabled.guard.ts b/error/isRouteEnabled.guard.ts index c03821b2..2c8d704c 100644 --- a/error/isRouteEnabled.guard.ts +++ b/error/isRouteEnabled.guard.ts @@ -23,7 +23,7 @@ export class IsRouteEnabled implements CanActivate { if (!community) { community = properties.adminToolsCommunity; } - return this.config.isPageEnabledByState(properties, community, '/' + path).pipe(take(1), tap((enabled) => { + return this.config.isPageEnabled(properties, community, '/' + path).pipe(take(1), tap((enabled) => { if (!enabled) { this.router.navigate([redirect], {queryParams: {'page': path}}); } diff --git a/fos/fos.component.ts b/fos/fos.component.ts index d6506428..da5850b9 100644 --- a/fos/fos.component.ts +++ b/fos/fos.component.ts @@ -64,7 +64,7 @@ export class FosComponent implements OnInit, OnDestroy { ngOnInit() { if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe()); } this.url = this.properties.domain + this.properties.baseLink + this._router.url; this.seoService.createLinkForCanonicalURL(this.url); diff --git a/landingPages/dataProvider/dataProvider.component.ts b/landingPages/dataProvider/dataProvider.component.ts index 70751b2d..625a6b49 100644 --- a/landingPages/dataProvider/dataProvider.component.ts +++ b/landingPages/dataProvider/dataProvider.component.ts @@ -377,7 +377,7 @@ export class DataProviderComponent { this.updateTitle(this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName); this.updateDescription((this.dataProviderInfo.description ? (this.dataProviderInfo.description.substr(0,157) + (this.dataProviderInfo.description.substr(0,157).length == 157?"...":"")) : (this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName))); if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name).subscribe()); } this.showLoading = false; diff --git a/landingPages/htmlProjectReport/htmlProjectReport.component.ts b/landingPages/htmlProjectReport/htmlProjectReport.component.ts index 664c1dde..24520ba7 100644 --- a/landingPages/htmlProjectReport/htmlProjectReport.component.ts +++ b/landingPages/htmlProjectReport/htmlProjectReport.component.ts @@ -171,7 +171,7 @@ export class HtmlProjectReportComponent { this.updateTitle(data.title + " " + this.resultsType + " report"); } if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, ((data.acronym) ? data.acronym : data.title) + " " + this.resultsType + " report", this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, ((data.acronym) ? data.acronym : data.title) + " " + this.resultsType + " report").subscribe()); } }, err => { diff --git a/landingPages/organization/organization.component.ts b/landingPages/organization/organization.component.ts index 475f280b..127a5135 100644 --- a/landingPages/organization/organization.component.ts +++ b/landingPages/organization/organization.component.ts @@ -395,7 +395,7 @@ export class OrganizationComponent { ((this.organizationInfo.title.name && this.organizationInfo.title.name != this.organizationInfo.name) ? (', ') : '') + (this.organizationInfo.name?this.organizationInfo.name:'')); if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.organizationInfo.title.name, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.organizationInfo.title.name).subscribe()); } var refineFields: string [] = ["funder"]; diff --git a/landingPages/project/project.component.ts b/landingPages/project/project.component.ts index 34e7d6e9..48577593 100644 --- a/landingPages/project/project.component.ts +++ b/landingPages/project/project.component.ts @@ -498,7 +498,7 @@ export class ProjectComponent { // this.updateDescription(this.projectInfo.description?this.projectInfo.description: ("project" + (this.projectInfo.title?"," + this.projectInfo.title:"") + (this.projectInfo.funding && this.projectInfo.funding.funderName?", funder: " + this.projectInfo.funding.funderName:"") + (this.projectInfo.acronym?"," + this.projectInfo.acronym:""))); this.updateDescription((this.projectInfo.description ? (this.projectInfo.description.substr(0,157) + (this.projectInfo.description.substr(0,157).length == 157?"...":"")) : (this.projectInfo.title))); if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.projectName, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.projectName).subscribe()); } this.project = { diff --git a/landingPages/result/resultLanding.component.ts b/landingPages/result/resultLanding.component.ts index 1ef770ad..f3ac4843 100644 --- a/landingPages/result/resultLanding.component.ts +++ b/landingPages/result/resultLanding.component.ts @@ -485,7 +485,7 @@ export class ResultLandingComponent { this.updateDescription((this.resultLandingInfo.description ? (this.resultLandingInfo.description.substr(0,157) + (this.resultLandingInfo.description.substr(0,157).length == 157?"...":"")) : (this.resultLandingInfo.title))); } if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackViewForCustomUrl(this.properties, this.resultLandingInfo.title, this.linkToLandingPage.split("?")[1] + this.id ,this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackViewForCustomUrl(this.properties, this.resultLandingInfo.title, this.linkToLandingPage.split("?")[1] + this.id).subscribe()); } let bioentitiesNum = 0; diff --git a/orcid/my-orcid-links/myOrcidLinks.component.ts b/orcid/my-orcid-links/myOrcidLinks.component.ts index f9d5ed0c..7811f1bb 100644 --- a/orcid/my-orcid-links/myOrcidLinks.component.ts +++ b/orcid/my-orcid-links/myOrcidLinks.component.ts @@ -188,7 +188,7 @@ export class MyOrcidLinksComponent { this.updateUrl( properties.domain + properties.baseLink + this.route.url); if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ - this.subscriptions.push(this._piwikService.trackView(this.properties, "My ORCID links", this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, "My ORCID links").subscribe()); } this.typeQuery = "&type=results"; diff --git a/sdg/sdg.component.ts b/sdg/sdg.component.ts index ac2ba65a..1a3dcb53 100644 --- a/sdg/sdg.component.ts +++ b/sdg/sdg.component.ts @@ -48,7 +48,7 @@ export class SdgComponent implements OnInit, OnDestroy { ngOnInit() { this.loading = true; if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe()); } this.url = this.properties.domain + this.properties.baseLink + this._router.url; this.seoService.createLinkForCanonicalURL(this.url); diff --git a/searchPages/find/searchAll.component.ts b/searchPages/find/searchAll.component.ts index 67b16706..be574fba 100644 --- a/searchPages/find/searchAll.component.ts +++ b/searchPages/find/searchAll.component.ts @@ -153,14 +153,14 @@ export class SearchAllComponent { this._meta.updateTag({content: url}, "property='og:url'"); this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url, false); if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { - this.subs.push(this._piwikService.trackView(this.properties, title, this.piwikSiteId).subscribe()); + this.subs.push(this._piwikService.trackView(this.properties, title).subscribe()); } if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || this.properties.adminToolsCommunity) { //this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => { - this.subs.push(this.config.communityInformationState.subscribe(data => { + this.subs.push(this.config.portalAsObservable.subscribe(data => { if(data && data['entities']) { var showEntity = {}; for (var i = 0; i < data['entities'].length; i++) { diff --git a/searchPages/searchUtils/entitiesSelection.component.ts b/searchPages/searchUtils/entitiesSelection.component.ts index 8b3759d2..d9da0d6d 100644 --- a/searchPages/searchUtils/entitiesSelection.component.ts +++ b/searchPages/searchUtils/entitiesSelection.component.ts @@ -41,7 +41,7 @@ export class EntitiesSelectionComponent { /** TODO change conditions base on PortalType instead of customFilter */ ngOnInit() { if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || (['explore', 'aggregator', 'eosc'].includes(this.properties.adminToolsPortalType))) { - this.subscriptions.push(this.config.communityInformationState.subscribe(data => { + this.subscriptions.push(this.config.portalAsObservable.subscribe(data => { if (data) { let showEntity = {}; let showPage = {}; diff --git a/searchPages/searchUtils/newSearchPage.component.ts b/searchPages/searchUtils/newSearchPage.component.ts index 6f6e5c10..87be8f9c 100644 --- a/searchPages/searchUtils/newSearchPage.component.ts +++ b/searchPages/searchUtils/newSearchPage.component.ts @@ -176,7 +176,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges { this.updateUrl(this.properties.domain + this.properties.baseLink + this.router.url); this.url = this.properties.domain + this.properties.baseLink + this.router.url; if (typeof document !== 'undefined' && this.isPiwikEnabled && !this.includeOnlyResultsAndFilter && this.piwikSiteId) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe()); } this.layoutService.isMobile.subscribe(isMobile => { this.isMobile = isMobile; @@ -353,7 +353,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges { localStorage.setItem('previousRoute', this.router.url); } if (this.isPiwikEnabled && (typeof document !== 'undefined') && this.piwikSiteId) { - this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe()); + this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe()); } /* End Piwik Code */ } diff --git a/sharedComponents/bottom.component.ts b/sharedComponents/bottom.component.ts index e8158bfa..dc6615fa 100644 --- a/sharedComponents/bottom.component.ts +++ b/sharedComponents/bottom.component.ts @@ -41,7 +41,7 @@ export class BottomComponent { if (this.showMenuItems) { if (this.properties.adminToolsAPIURL && this.communityId) { //this.subs.push(this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => { - this.subs.push(this.config.communityInformationState.subscribe(data => { + this.subs.push(this.config.portalAsObservable.subscribe(data => { if (data) { for (var i = 0; i < data['pages'].length; i++) { this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"]; diff --git a/sharedComponents/navigationBar.component.ts b/sharedComponents/navigationBar.component.ts index 4f3cf8e4..78259077 100644 --- a/sharedComponents/navigationBar.component.ts +++ b/sharedComponents/navigationBar.component.ts @@ -106,7 +106,7 @@ export class NavigationBarComponent implements OnInit, OnDestroy, OnChanges { this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user); if ((this.properties.adminToolsAPIURL && this.communityId) || properties.adminToolsPortalType == "community") { //this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => { - this.subs.push(this.config.communityInformationState.subscribe(data => { + this.subs.push(this.config.portalAsObservable.subscribe(data => { if (data) { this.showEntity = {}; this.showPage = {}; diff --git a/utils/configuration/configuration.service.ts b/utils/configuration/configuration.service.ts index 33a11e28..1d28bbef 100644 --- a/utils/configuration/configuration.service.ts +++ b/utils/configuration/configuration.service.ts @@ -1,15 +1,15 @@ -import {Injectable, OnDestroy} from '@angular/core'; +import {Injectable} from '@angular/core'; import {HttpClient} from "@angular/common/http"; -import {BehaviorSubject, from, Observable, of, Subscription} from 'rxjs'; -import {map} from 'rxjs/operators'; +import {from, Observable, Subscription} from 'rxjs'; import {EnvProperties} from "../properties/env-properties"; import {Portal} from "../entities/adminTool/portal"; import {Page} from "../entities/adminTool/page"; import {properties} from "../../../../environments/environment"; +import {AdvancedAsyncSubject} from "../AdvancedAsyncSubject"; @Injectable({providedIn: 'root'}) export class ConfigurationService { - private communityInformation: BehaviorSubject = new BehaviorSubject(null); + private portal: AdvancedAsyncSubject = new AdvancedAsyncSubject(); private sub: Subscription = null; private promise: Promise = null; @@ -26,73 +26,34 @@ export class ConfigurationService { } } - /** - * @deprecated - */ - getCommunityInformation(properties: EnvProperties, community: string) { - let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + community + '/full'; - return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); - //.map(res => res.json()); - } - - public initStaticCommunityInformation(communityInformation: Portal) { - this.promise = new Promise((resolve => { - this.communityInformation.next(communityInformation); - resolve(); - })); - } - - public initCommunityInformation(properties: EnvProperties, community: string) { - if (community == null) return; - let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + community + "/full"; + public initPortal(properties: EnvProperties, pid: string) { + if (pid == null) return; + let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + pid + "/full"; this.promise = new Promise((resolve => { this.sub = this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe( (communityInformation: Portal) => { - this.communityInformation.next(communityInformation); + this.portal.next(communityInformation); resolve(); }, error => { - this.communityInformation.error(error); + this.portal.error(error); resolve(); }); })); } - public get communityInformationState(): Observable { - return this.communityInformation.asObservable(); + public get portalAsObservable(): Observable { + return this.portal.asObservable(); } - /** - * @deprecated - */ - isEntityEnabled(APIUrl: string, community: string, entity: string) { - //console.log("isEntityEnabled: "+entity); - let url = "isEntityEnabled-" + entity; - - // if(entity == "publication" || entity == "dataset" || entity == "datasource"){ - // return Observable.of(new Object()).mapTo(false); - // } - // return Observable.of(new Object()).mapTo(true); - return this.http.get(APIUrl + "/page") - .pipe(map(res => true)); + get piwik() { + return this.portal.value?.piwik ? this.portal.value.piwik : properties.piwikSiteId; } - isPageEnabled(portal: string, route: string, portalType = properties.adminToolsPortalType) { - let url = properties.adminToolsAPIURL + "/" + portalType + "/" + portal + "/pages?page_route=" + route; - return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => { - let result = false; - if (res['length'] > 0 && res[0].route == route) { - result = res[0].isEnabled; - } - return result; - })); - } - - async isPageEnabledByStateAsync(properties: EnvProperties, portal: string, page_route: string) { - if (!this.promise || (this.communityInformation && this.communityInformation.getValue() && portal !== this.communityInformation.getValue().pid)) { - this.initCommunityInformation(properties, portal); + async isPageEnabledAsync(properties: EnvProperties, portal: string, page_route: string) { + if (!this.promise || (this.portal && this.portal.getValue() && portal !== this.portal.getValue().pid)) { + this.initPortal(properties, portal); } await this.promise; @@ -102,13 +63,13 @@ export class ConfigurationService { return this.filtering(page_route); } - isPageEnabledByState(properties: EnvProperties, portal: string, router: string): Observable { + isPageEnabled(properties: EnvProperties, portal: string, router: string): Observable { let page_route: string = router.split('?')[0].substring(1); - return from(this.isPageEnabledByStateAsync(properties, portal, page_route)); + return from(this.isPageEnabledAsync(properties, portal, page_route)); } filtering(page_route: string) { - let community: Portal = this.communityInformation.getValue(); + let community: Portal = this.portal.getValue(); let pages: Page[] = community.pages; if (pages) { let page = pages.find((page: Page) => page.route == page_route); @@ -117,38 +78,4 @@ export class ConfigurationService { return false; } } - - /** - * @deprecated - */ - getMainPageContent(APIUrl: string, community: string,) { - return this.http.get(APIUrl + "/page") - .pipe(map(res => true)); - } - - /** - * @deprecated - */ - getSpecialAnouncementContent(APIUrl: string, community: string,) { - return this.http.get(APIUrl + "/page") - .pipe(map(res => "")); - } - - /** - * @deprecated - */ - getHelpPageContent(APIUrl: string, community: string, router: string) { - return this.http.get(APIUrl + "/page") - .pipe(map(res => true)); - } - - // private handleError (error: Response) { - // // in a real world app, we may send the error to some remote logging infrastructure - // // instead of just logging it to the console - // console.log(error); - // return this.http.get(this.APIUrl + "/page") - // .map(res => true); - // } - - } diff --git a/utils/piwik/piwik.service.ts b/utils/piwik/piwik.service.ts index 379f5e6b..769e0e99 100644 --- a/utils/piwik/piwik.service.ts +++ b/utils/piwik/piwik.service.ts @@ -4,75 +4,85 @@ import {HttpClient} from "@angular/common/http"; import {StringUtils} from '../string-utils.class'; import {EnvProperties} from '../properties/env-properties'; import {Observable} from "rxjs"; +import {ConfigurationService} from "../configuration/configuration.service"; @Injectable() export class PiwikService { - constructor(private http: HttpClient ) {} - trackViewForCustomUrl (properties:EnvProperties, title, pageparams, siteId = null):any { - let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId); - if(typeof location !== 'undefined' && piwikId){ - return this.doTrackView(properties,title,piwikId,location.href.split("?")[0] + "?" + pageparams); + constructor(private http: HttpClient, private configurationService: ConfigurationService) { + } + + trackViewForCustomUrl(properties: EnvProperties, title, pageparams): any { + let piwikId = this.configurationService.piwik; + if (typeof location !== 'undefined' && piwikId) { + return this.doTrackView(properties, title, piwikId, location.href.split("?")[0] + "?" + pageparams); } } - trackView (properties:EnvProperties, title, siteId = null):any { - let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId); - if(typeof location !== 'undefined' && piwikId){ - return this.doTrackView(properties,title,piwikId,location.href); - } + + trackView(properties: EnvProperties, title): any { + let piwikId = this.configurationService.piwik; + console.log(piwikId); + if (typeof location !== 'undefined' && piwikId) { + return this.doTrackView(properties, title, piwikId, location.href); } - private doTrackView (properties:EnvProperties, title, siteId, pageURL):any { - + } + + private doTrackView(properties: EnvProperties, title, siteId, pageURL): any { + let ua = this.getUserAgent(); let referrer = this.getReferrer(); - let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId); - if(typeof location !== 'undefined' && piwikId){ + let piwikId = ((siteId != null) ? siteId : properties.piwikSiteId); + if (typeof location !== 'undefined' && piwikId) { // console.log("Piwik - View: " + pageURL, title); - var url = properties.piwikBaseUrl+piwikId+"&rec=1&url="+StringUtils.URIEncode(pageURL)+"&action_name="+StringUtils.URIEncode(title)+ - ((ua != null && ua.length > 0)?('&ua='+StringUtils.URIEncode(ua)):'')+ - ((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):''); + var url = properties.piwikBaseUrl + piwikId + "&rec=1&url=" + StringUtils.URIEncode(pageURL) + "&action_name=" + StringUtils.URIEncode(title) + + ((ua != null && ua.length > 0) ? ('&ua=' + StringUtils.URIEncode(ua)) : '') + + ((referrer != null && referrer.length > 0) ? ('&urlref=' + StringUtils.URIEncode(referrer)) : ''); // console.log("Piwik - View: " + url); // return Observable.of(new Object()); // for testing - return this.http.get( url, {responseType: 'blob'}); + return this.http.get(url, {responseType: 'blob'}); // .do(request => console.info("Piwik request completed" )); - + } } - trackDownload (properties:EnvProperties, type = "", siteId = null):any { - var ua = this.getUserAgent(); - var referrer = this.getReferrer(); - var url = properties.piwikBaseUrl+((siteId!=null)?siteId:properties.piwikSiteId)+"&rec=1&url="+StringUtils.URIEncode(location.href)+"&download="+StringUtils.URIEncode(location.href+"#"+type)+ - ((ua != null && ua.length > 0)?('&ua='+StringUtils.URIEncode(ua)):'')+ - ((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):''); - //console.log("Piwik - trackDownload: "+url); - - return this.http.get( url, {responseType: 'blob'}); - //.do(request => console.info("Piwik request completed" )); - + + trackDownload(properties: EnvProperties, type = "", siteId = null): any { + var ua = this.getUserAgent(); + var referrer = this.getReferrer(); + var url = properties.piwikBaseUrl + ((siteId != null) ? siteId : properties.piwikSiteId) + "&rec=1&url=" + StringUtils.URIEncode(location.href) + "&download=" + StringUtils.URIEncode(location.href + "#" + type) + + ((ua != null && ua.length > 0) ? ('&ua=' + StringUtils.URIEncode(ua)) : '') + + ((referrer != null && referrer.length > 0) ? ('&urlref=' + StringUtils.URIEncode(referrer)) : ''); + //console.log("Piwik - trackDownload: "+url); + + return this.http.get(url, {responseType: 'blob'}); + //.do(request => console.info("Piwik request completed" )); + + } + + private getUserAgent() { + if (typeof navigator !== 'undefined') { + //console.log("navigator.userAgent:" + navigator.userAgent); + return navigator.userAgent; + + } else { + return null; } - private getUserAgent(){ - if (typeof navigator !== 'undefined') { - //console.log("navigator.userAgent:" + navigator.userAgent); - return navigator.userAgent; - - }else{ - return null; - } + } + + private getReferrer() { + var referrer = ""; + if (typeof document !== 'undefined') { + //console.log("document.referrer:" + document.referrer); + referrer = document.referrer; + } - private getReferrer(){ - var referrer = ""; - if (typeof document !== 'undefined') { - //console.log("document.referrer:" + document.referrer); - referrer = document.referrer; - - } - if((referrer == null || referrer.length == 0)&&typeof localStorage !== 'undefined'){ - - referrer =localStorage.getItem('previousRoute'); - } - return referrer; + if ((referrer == null || referrer.length == 0) && typeof localStorage !== 'undefined') { + + referrer = localStorage.getItem('previousRoute'); } - parse(data:any){ - } - + return referrer; + } + + parse(data: any) { + } + }