2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Http, Response, Headers, RequestOptions, URLSearchParams} from '@angular/http';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Location} from '@angular/common';
|
|
|
|
|
|
|
|
import {StringUtils} from '../string-utils.class';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {EnvProperties} from '../properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class PiwikService {
|
|
|
|
private piwikbaseUrl:string = "";
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient, private location: Location ) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-04-11 10:59:01 +02:00
|
|
|
trackView (properties:EnvProperties, title, siteId = null):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
var ua = this.getUserAgent();
|
|
|
|
var referrer = this.getReferrer();
|
|
|
|
if(typeof location !== 'undefined'){
|
2018-04-11 10:59:01 +02:00
|
|
|
var url = properties.piwikBaseUrl+((siteId!=null)?siteId:properties.piwikSiteId)+"&rec=1&url="+StringUtils.URIEncode(location.href)+"&action_name="+StringUtils.URIEncode(title)+
|
2017-12-19 13:53:46 +01:00
|
|
|
((ua != null && ua.length > 0)?('&ua='+StringUtils.URIEncode(ua)):'')+
|
|
|
|
((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):'');
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Piwik - View: " + url);
|
2018-06-11 10:23:04 +02:00
|
|
|
// return Observable.of(new Object()).mapTo(true); // for testing
|
2019-08-02 17:49:41 +02:00
|
|
|
return this.http.get( url, {responseType: 'blob'});
|
|
|
|
// .do(request => console.info("Piwik request completed" ));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 10:59:01 +02:00
|
|
|
trackDownload (properties:EnvProperties, downloadURL, siteId = null):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
var ua = this.getUserAgent();
|
|
|
|
var referrer = this.getReferrer();
|
2018-04-11 10:59:01 +02:00
|
|
|
var url = properties.piwikBaseUrl+((siteId!=null)?siteId:properties.piwikSiteId)+"&rec=1&url="+StringUtils.URIEncode(downloadURL)+"&download="+StringUtils.URIEncode(downloadURL)+
|
2017-12-19 13:53:46 +01:00
|
|
|
((ua != null && ua.length > 0)?('&ua='+StringUtils.URIEncode(ua)):'')+
|
|
|
|
((referrer != null && referrer.length > 0)?('&urlref='+StringUtils.URIEncode(referrer)):'');
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Piwik - trackDownload: "+url);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-08-02 17:49:41 +02:00
|
|
|
return this.http.get( url, {responseType: 'blob'});
|
2019-02-14 11:44:30 +01:00
|
|
|
//.do(request => console.info("Piwik request completed" ));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
private getUserAgent(){
|
|
|
|
if (typeof navigator !== 'undefined') {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("navigator.userAgent:" + navigator.userAgent);
|
2017-12-19 13:53:46 +01:00
|
|
|
return navigator.userAgent;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private getReferrer(){
|
|
|
|
var referrer = "";
|
|
|
|
if (typeof document !== 'undefined') {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("document.referrer:" + document.referrer);
|
2017-12-19 13:53:46 +01:00
|
|
|
referrer = document.referrer;
|
|
|
|
|
|
|
|
}
|
|
|
|
if((referrer == null || referrer.length == 0)&&typeof localStorage !== 'undefined'){
|
|
|
|
|
|
|
|
referrer =localStorage.getItem('previousRoute');
|
|
|
|
}
|
|
|
|
return referrer;
|
|
|
|
}
|
|
|
|
parse(data:any){
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|