Change piwik service methods in order to get the piwik from portal configuration

This commit is contained in:
Konstantinos Triantafyllou 2023-04-26 14:10:45 +03:00
parent c547dfa945
commit 49e2edfe84
19 changed files with 101 additions and 164 deletions

View File

@ -111,7 +111,7 @@ export class DisplayClaimsComponent implements OnInit, OnDestroy {
this.updateDescription(description); this.updateDescription(description);
this.updateUrl(this.url); this.updateUrl(this.url);
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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 => { this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {

View File

@ -75,7 +75,7 @@ export class LinkingGenericComponent {
this.seoService.createLinkForCanonicalURL(this.url, false); this.seoService.createLinkForCanonicalURL(this.url, false);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ 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 => { this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {

View File

@ -203,7 +203,7 @@ export class DepositFirstPageComponent {
} }
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ 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}); this.breadcrumbs.push({name: 'home', route: '/'}, {name: "Deposit", route: null});
} }

View File

@ -23,7 +23,7 @@ export class IsRouteEnabled implements CanActivate {
if (!community) { if (!community) {
community = properties.adminToolsCommunity; 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) { if (!enabled) {
this.router.navigate([redirect], {queryParams: {'page': path}}); this.router.navigate([redirect], {queryParams: {'page': path}});
} }

View File

@ -64,7 +64,7 @@ export class FosComponent implements OnInit, OnDestroy {
ngOnInit() { ngOnInit() {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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.url = this.properties.domain + this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url); this.seoService.createLinkForCanonicalURL(this.url);

View File

@ -377,7 +377,7 @@ export class DataProviderComponent {
this.updateTitle(this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName); 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))); 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')) { 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; this.showLoading = false;

View File

@ -171,7 +171,7 @@ export class HtmlProjectReportComponent {
this.updateTitle(data.title + " " + this.resultsType + " report"); this.updateTitle(data.title + " " + this.resultsType + " report");
} }
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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 => { err => {

View File

@ -395,7 +395,7 @@ export class OrganizationComponent {
((this.organizationInfo.title.name && this.organizationInfo.title.name != this.organizationInfo.name) ? (', ') : '') + ((this.organizationInfo.title.name && this.organizationInfo.title.name != this.organizationInfo.name) ? (', ') : '') +
(this.organizationInfo.name?this.organizationInfo.name:'')); (this.organizationInfo.name?this.organizationInfo.name:''));
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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"]; var refineFields: string [] = ["funder"];

View File

@ -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: ("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))); 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')) { 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 = { this.project = {

View File

@ -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))); 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')) { 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; let bioentitiesNum = 0;

View File

@ -188,7 +188,7 @@ export class MyOrcidLinksComponent {
this.updateUrl( properties.domain + properties.baseLink + this.route.url); this.updateUrl( properties.domain + properties.baseLink + this.route.url);
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ 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"; this.typeQuery = "&type=results";

View File

@ -48,7 +48,7 @@ export class SdgComponent implements OnInit, OnDestroy {
ngOnInit() { ngOnInit() {
this.loading = true; this.loading = true;
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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.url = this.properties.domain + this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url); this.seoService.createLinkForCanonicalURL(this.url);

View File

@ -153,14 +153,14 @@ export class SearchAllComponent {
this._meta.updateTag({content: url}, "property='og:url'"); this._meta.updateTag({content: url}, "property='og:url'");
this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url, false); this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url, false);
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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) { 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.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']) { if(data && data['entities']) {
var showEntity = {}; var showEntity = {};
for (var i = 0; i < data['entities'].length; i++) { for (var i = 0; i < data['entities'].length; i++) {

View File

@ -41,7 +41,7 @@ export class EntitiesSelectionComponent {
/** TODO change conditions base on PortalType instead of customFilter */ /** TODO change conditions base on PortalType instead of customFilter */
ngOnInit() { ngOnInit() {
if ((this.customFilter && this.customFilter.queryFieldName == "communityId") || (['explore', 'aggregator', 'eosc'].includes(this.properties.adminToolsPortalType))) { 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) { if (data) {
let showEntity = {}; let showEntity = {};
let showPage = {}; let showPage = {};

View File

@ -176,7 +176,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges {
this.updateUrl(this.properties.domain + this.properties.baseLink + this.router.url); this.updateUrl(this.properties.domain + this.properties.baseLink + this.router.url);
this.url = 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) { 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.layoutService.isMobile.subscribe(isMobile => {
this.isMobile = isMobile; this.isMobile = isMobile;
@ -353,7 +353,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges {
localStorage.setItem('previousRoute', this.router.url); localStorage.setItem('previousRoute', this.router.url);
} }
if (this.isPiwikEnabled && (typeof document !== 'undefined') && this.piwikSiteId) { 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 */ /* End Piwik Code */
} }

View File

@ -41,7 +41,7 @@ export class BottomComponent {
if (this.showMenuItems) { if (this.showMenuItems) {
if (this.properties.adminToolsAPIURL && this.communityId) { if (this.properties.adminToolsAPIURL && this.communityId) {
//this.subs.push(this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => { //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) { if (data) {
for (var i = 0; i < data['pages'].length; i++) { for (var i = 0; i < data['pages'].length; i++) {
this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"]; this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];

View File

@ -106,7 +106,7 @@ export class NavigationBarComponent implements OnInit, OnDestroy, OnChanges {
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user); this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
if ((this.properties.adminToolsAPIURL && this.communityId) || properties.adminToolsPortalType == "community") { if ((this.properties.adminToolsAPIURL && this.communityId) || properties.adminToolsPortalType == "community") {
//this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => { //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) { if (data) {
this.showEntity = {}; this.showEntity = {};
this.showPage = {}; this.showPage = {};

View File

@ -1,15 +1,15 @@
import {Injectable, OnDestroy} from '@angular/core'; import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {BehaviorSubject, from, Observable, of, Subscription} from 'rxjs'; import {from, Observable, Subscription} from 'rxjs';
import {map} from 'rxjs/operators';
import {EnvProperties} from "../properties/env-properties"; import {EnvProperties} from "../properties/env-properties";
import {Portal} from "../entities/adminTool/portal"; import {Portal} from "../entities/adminTool/portal";
import {Page} from "../entities/adminTool/page"; import {Page} from "../entities/adminTool/page";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {AdvancedAsyncSubject} from "../AdvancedAsyncSubject";
@Injectable({providedIn: 'root'}) @Injectable({providedIn: 'root'})
export class ConfigurationService { export class ConfigurationService {
private communityInformation: BehaviorSubject<Portal> = new BehaviorSubject(null); private portal: AdvancedAsyncSubject<Portal> = new AdvancedAsyncSubject<Portal>();
private sub: Subscription = null; private sub: Subscription = null;
private promise: Promise<void> = null; private promise: Promise<void> = null;
@ -26,73 +26,34 @@ export class ConfigurationService {
} }
} }
/** public initPortal(properties: EnvProperties, pid: string) {
* @deprecated if (pid == null) return;
*/ let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + pid + "/full";
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<void>((resolve => {
this.communityInformation.next(communityInformation);
resolve();
}));
}
public initCommunityInformation(properties: EnvProperties, community: string) {
if (community == null) return;
let url = properties.adminToolsAPIURL + "/" + properties.adminToolsPortalType + "/" + community + "/full";
this.promise = new Promise<void>((resolve => { this.promise = new Promise<void>((resolve => {
this.sub = this.http.get<Portal>((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe( this.sub = this.http.get<Portal>((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe(
(communityInformation: Portal) => { (communityInformation: Portal) => {
this.communityInformation.next(communityInformation); this.portal.next(communityInformation);
resolve(); resolve();
}, },
error => { error => {
this.communityInformation.error(error); this.portal.error(error);
resolve(); resolve();
}); });
})); }));
} }
public get communityInformationState(): Observable<Portal> { public get portalAsObservable(): Observable<Portal> {
return this.communityInformation.asObservable(); return this.portal.asObservable();
} }
/** get piwik() {
* @deprecated return this.portal.value?.piwik ? this.portal.value.piwik : properties.piwikSiteId;
*/
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));
} }
isPageEnabled(portal: string, route: string, portalType = properties.adminToolsPortalType) { async isPageEnabledAsync(properties: EnvProperties, portal: string, page_route: string) {
let url = properties.adminToolsAPIURL + "/" + portalType + "/" + portal + "/pages?page_route=" + route; if (!this.promise || (this.portal && this.portal.getValue() && portal !== this.portal.getValue().pid)) {
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) this.initPortal(properties, portal);
.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);
} }
await this.promise; await this.promise;
@ -102,13 +63,13 @@ export class ConfigurationService {
return this.filtering(page_route); return this.filtering(page_route);
} }
isPageEnabledByState(properties: EnvProperties, portal: string, router: string): Observable<boolean> { isPageEnabled(properties: EnvProperties, portal: string, router: string): Observable<boolean> {
let page_route: string = router.split('?')[0].substring(1); 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) { filtering(page_route: string) {
let community: Portal = this.communityInformation.getValue(); let community: Portal = this.portal.getValue();
let pages: Page[] = <Page[]>community.pages; let pages: Page[] = <Page[]>community.pages;
if (pages) { if (pages) {
let page = pages.find((page: Page) => page.route == page_route); let page = pages.find((page: Page) => page.route == page_route);
@ -117,38 +78,4 @@ export class ConfigurationService {
return false; 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);
// }
} }

View File

@ -4,75 +4,85 @@ import {HttpClient} from "@angular/common/http";
import {StringUtils} from '../string-utils.class'; import {StringUtils} from '../string-utils.class';
import {EnvProperties} from '../properties/env-properties'; import {EnvProperties} from '../properties/env-properties';
import {Observable} from "rxjs"; import {Observable} from "rxjs";
import {ConfigurationService} from "../configuration/configuration.service";
@Injectable() @Injectable()
export class PiwikService { export class PiwikService {
constructor(private http: HttpClient ) {} constructor(private http: HttpClient, private configurationService: ConfigurationService) {
trackViewForCustomUrl (properties:EnvProperties, title, pageparams, siteId = null):any { }
let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId);
if(typeof location !== 'undefined' && piwikId){ trackViewForCustomUrl(properties: EnvProperties, title, pageparams): any {
return this.doTrackView(properties,title,piwikId,location.href.split("?")[0] + "?" + pageparams); 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); trackView(properties: EnvProperties, title): any {
if(typeof location !== 'undefined' && piwikId){ let piwikId = this.configurationService.piwik;
return this.doTrackView(properties,title,piwikId,location.href); 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 ua = this.getUserAgent();
let referrer = this.getReferrer(); let referrer = this.getReferrer();
let piwikId= ((siteId!=null)?siteId:properties.piwikSiteId); let piwikId = ((siteId != null) ? siteId : properties.piwikSiteId);
if(typeof location !== 'undefined' && piwikId){ if (typeof location !== 'undefined' && piwikId) {
// console.log("Piwik - View: " + pageURL, title); // console.log("Piwik - View: " + pageURL, title);
var url = properties.piwikBaseUrl+piwikId+"&rec=1&url="+StringUtils.URIEncode(pageURL)+"&action_name="+StringUtils.URIEncode(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)):'')+ ((ua != null && ua.length > 0) ? ('&ua=' + StringUtils.URIEncode(ua)) : '') +
((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):''); ((referrer != null && referrer.length > 0) ? ('&urlref=' + StringUtils.URIEncode(referrer)) : '');
// console.log("Piwik - View: " + url); // console.log("Piwik - View: " + url);
// return Observable.of(new Object()); // for testing // 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" )); // .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'}); trackDownload(properties: EnvProperties, type = "", siteId = null): any {
//.do(request => console.info("Piwik request completed" )); 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 getReferrer() {
var referrer = "";
if (typeof document !== 'undefined') {
//console.log("document.referrer:" + document.referrer);
referrer = document.referrer;
} }
private getUserAgent(){ if ((referrer == null || referrer.length == 0) && typeof localStorage !== 'undefined') {
if (typeof navigator !== 'undefined') {
//console.log("navigator.userAgent:" + navigator.userAgent);
return navigator.userAgent;
}else{ referrer = localStorage.getItem('previousRoute');
return null;
}
} }
private getReferrer(){ return referrer;
var referrer = ""; }
if (typeof document !== 'undefined') {
//console.log("document.referrer:" + document.referrer);
referrer = document.referrer;
} parse(data: any) {
if((referrer == null || referrer.length == 0)&&typeof localStorage !== 'undefined'){ }
referrer =localStorage.getItem('previousRoute');
}
return referrer;
}
parse(data:any){
}
} }