Skip to content
Snippets Groups Projects
Commit eb7245e4 authored by ncastejon's avatar ncastejon
Browse files

Variabilize the matomo id and url servers inside the docker integration

parent 2c881079
No related branches found
No related tags found
No related merge requests found
Pipeline #
Showing
with 108 additions and 22 deletions
...@@ -28,6 +28,8 @@ deploy_development: ...@@ -28,6 +28,8 @@ deploy_development:
- sandbox - sandbox
script: script:
- export NGINX_PORT=8081 - export NGINX_PORT=8081
- export MATOMO_SITE_ID=1
- export MATOMO_SERVER_URL=https://matomo-intothesky.alpha.grandlyon.com
- docker-compose --project-name data-reloaded-dev up -d - docker-compose --project-name data-reloaded-dev up -d
environment: environment:
name: development name: development
...@@ -47,6 +49,8 @@ deploy_staging: ...@@ -47,6 +49,8 @@ deploy_staging:
- staging - staging
script: script:
- export NGINX_PORT=8080 - export NGINX_PORT=8080
- export MATOMO_SITE_ID=3
- export MATOMO_SERVER_URL=https://matomo-intothesky.alpha.grandlyon.com
- docker-compose --project-name data-reloaded-rec up -d - docker-compose --project-name data-reloaded-rec up -d
environment: environment:
name: staging name: staging
......
...@@ -5,7 +5,12 @@ services: ...@@ -5,7 +5,12 @@ services:
build: build:
context: ./ context: ./
volumes: volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf - ./nginx.conf.template:/etc/nginx/nginx.conf.template
ports: ports:
- ${NGINX_PORT}:8080 - ${NGINX_PORT}:8080
command: >
/bin/sh -c
'echo $MATOMO_SITE_ID && sed "s#<MATOMO_SITE_ID>#$MATOMO_SITE_ID#g; s#<MATOMO_SERVER_URL>#$MATOMO_SERVER_URL#g" /etc/nginx/nginx.conf.template
> /etc/nginx/conf.d/default.conf
&& nginx -g "daemon off;"'
\ No newline at end of file
...@@ -4,6 +4,25 @@ server { ...@@ -4,6 +4,25 @@ server {
server_name _; server_name _;
root /usr/share/nginx/html/; root /usr/share/nginx/html/;
set $matomo_script
"<script type='text/javascript'>
var _paq = _paq || [];
var siteId = <MATOMO_SITE_ID>;
window['siteId'] = siteId;
_paq.push(['enableLinkTracking']);
(function() {
var u='<MATOMO_SERVER_URL>/';
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', siteId]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>";
sub_filter '</head>' '$matomo_script</head>';
# rule redirecting to fr or en regarding the browser preferences # rule redirecting to fr or en regarding the browser preferences
location = / { location = / {
rewrite_by_lua ' rewrite_by_lua '
......
...@@ -2,6 +2,8 @@ import { TestBed, async } from '@angular/core/testing'; ...@@ -2,6 +2,8 @@ import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { MockComponent } from 'ng2-mock-component'; import { MockComponent } from 'ng2-mock-component';
import { RouterTestingModule } from '../../node_modules/@angular/router/testing'; import { RouterTestingModule } from '../../node_modules/@angular/router/testing';
import { Angulartics2Module } from 'angulartics2';
import { Angulartics2Piwik } from 'angulartics2/piwik';
describe('AppComponent', () => { describe('AppComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
...@@ -15,6 +17,7 @@ describe('AppComponent', () => { ...@@ -15,6 +17,7 @@ describe('AppComponent', () => {
], ],
imports: [ imports: [
RouterTestingModule, RouterTestingModule,
Angulartics2Module.forRoot([Angulartics2Piwik]),
], ],
}).compileComponents(); }).compileComponents();
})); }));
......
import { Notification, INotification } from './notification.model'; import { Notification, INotification } from './notification.model';
import { IMatomoResponse } from './matomo.model';
export { Notification, INotification }; export { Notification, INotification };
export { IMatomoResponse };
export interface IMatomoResponse {
nb_visits: number;
}
import { ErrorService } from './error.service'; import { ErrorService } from './error.service';
import { NotificationService } from './notification.service'; import { NotificationService } from './notification.service';
import { MatomoService } from './matomo.service';
export { ErrorService }; export { ErrorService };
export { NotificationService }; export { NotificationService };
export { MatomoService };
// tslint:disable-next-line:variable-name // tslint:disable-next-line:variable-name
export const CoreServices = [ export const CoreServices = [
ErrorService, ErrorService,
NotificationService, NotificationService,
MatomoService,
]; ];
import { Injectable } from '@angular/core';
import { IMatomoResponse } from '../models/matomo.model';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { map, catchError } from 'rxjs/operators';
import { environment } from '../../../environments/environment';
import { ErrorService } from './error.service';
import { errors } from '../../../i18n/error-messages/error-messages';
@Injectable()
export class MatomoService {
constructor(
private http: HttpClient,
private _errorService: ErrorService,
) { }
getPageMetadataPageMetrics(metadataId: string): Observable<number> {
const dateNowString = new Date().toISOString().slice(0, 10);
const dateOneMonthAgo = new Date();
dateOneMonthAgo.setMonth(new Date().getMonth() - 1);
const dateOneMonthAgoString = dateOneMonthAgo.toISOString().slice(0, 10);
const url = environment.matomo.url + '/?module=API&method=Actions.getPageUrls' +
'&idSite=' + window['siteId'] + '&format=json&period=range&date=' + dateOneMonthAgoString
+ ',' + dateNowString +
'&segment=pageUrl=@' + metadataId + '/info';
return this.http.get<IMatomoResponse[]>(url).pipe(
map((results) => {
return results.length > 0 ? results.reduce((a, b) => a + b.nb_visits, 0) : 0;
}),
catchError(
(err) => {
throw this._errorService.handleError(err, { message: errors.matomo.getViews });
},
));
}
}
...@@ -56,6 +56,7 @@ const metadata = { ...@@ -56,6 +56,7 @@ const metadata = {
max_north: 4, max_north: 4,
updateFrequency: '', updateFrequency: '',
max_west: 4, max_west: 4,
nbViews: 10,
crs: '', crs: '',
image: { image: {
url: '', url: '',
......
...@@ -78,11 +78,11 @@ ...@@ -78,11 +78,11 @@
</span> </span>
{{ formatDate(dataset.metadata.geonet.changeDate,'dd MMMM yyyy')}} {{ formatDate(dataset.metadata.geonet.changeDate,'dd MMMM yyyy')}}
</p> </p>
<p> <p *ngIf="dataset.metadata.nbViews">
<span class="icon"> <span class="icon">
<i class="far fa-eye"></i> <i class="far fa-eye"></i>
</span> </span>
{{ dataset.metadata.popularity || '-' }} {{ dataset.metadata.nbViews || '-' }}
</p> </p>
</div> </div>
</div> </div>
......
...@@ -10,6 +10,7 @@ import { Notification } from '../../../core/models'; ...@@ -10,6 +10,7 @@ import { Notification } from '../../../core/models';
import { DatePipe } from '../../../../../node_modules/@angular/common'; import { DatePipe } from '../../../../../node_modules/@angular/common';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { MatomoService } from '../../../core/services/matomo.service';
@Component({ @Component({
selector: 'app-dataset-list', selector: 'app-dataset-list',
...@@ -34,7 +35,7 @@ export class DatasetListComponent implements OnInit, OnDestroy { ...@@ -34,7 +35,7 @@ export class DatasetListComponent implements OnInit, OnDestroy {
private _router: Router, private _router: Router,
private _notificationService: NotificationService, private _notificationService: NotificationService,
private _datePipe: DatePipe, private _datePipe: DatePipe,
private _http: HttpClient, private _matomoService: MatomoService,
) { } ) { }
ngOnInit() { ngOnInit() {
...@@ -73,11 +74,16 @@ export class DatasetListComponent implements OnInit, OnDestroy { ...@@ -73,11 +74,16 @@ export class DatasetListComponent implements OnInit, OnDestroy {
this.loading = false; this.loading = false;
window.scrollTo(0, yPageOffset); window.scrollTo(0, yPageOffset);
// const url = 'http://localhost:8181/piwik.php?search=' // Get the page views for each dataset
// + this._datasetResearchService.searchString this.datasetList.forEach((dataset) => {
// + '&idsite=1&rec=1'; this._matomoService.getPageMetadataPageMetrics(dataset.metadata.geonet.uuid).subscribe(
// console.log(url); (views) => {
// this._http.get(url).subscribe(); dataset.metadata.nbViews = views;
},
(err) => {
});
});
}, },
(err) => { (err) => {
this._notificationService.notify(new Notification({ this._notificationService.notify(new Notification({
......
...@@ -131,6 +131,7 @@ export class Metadata { ...@@ -131,6 +131,7 @@ export class Metadata {
url: string; url: string;
type: string; type: string;
}; };
'nbViews': number;
constructor(data?: IMetadata) { constructor(data?: IMetadata) {
if (data) { if (data) {
......
...@@ -15,6 +15,10 @@ export const environment = { ...@@ -15,6 +15,10 @@ export const environment = {
meta: servicesProxyUrl + '/elasticsearch/*.meta', meta: servicesProxyUrl + '/elasticsearch/*.meta',
}, },
matomo: {
url: 'https://matomo-intothesky.alpha.grandlyon.com',
},
// Path to the built app in a particular language // Path to the built app in a particular language
angularAppHost: { angularAppHost: {
fr: '/fr', fr: '/fr',
......
...@@ -15,6 +15,10 @@ export const environment = { ...@@ -15,6 +15,10 @@ export const environment = {
meta: servicesProxyUrl + '/elasticsearch/*.meta', meta: servicesProxyUrl + '/elasticsearch/*.meta',
}, },
matomo: {
url: 'https://matomo-intothesky.alpha.grandlyon.com',
},
// Path to the built app in a particular language // Path to the built app in a particular language
angularAppHost: { angularAppHost: {
fr: '/fr', fr: '/fr',
......
...@@ -18,4 +18,7 @@ export const errors = { ...@@ -18,4 +18,7 @@ export const errors = {
getDatasetChildren: 'Impossible de récupérer les enfants du jeu de données', getDatasetChildren: 'Impossible de récupérer les enfants du jeu de données',
getDatasetTitle: 'Impossible de récupérer le titre du jeu de données', getDatasetTitle: 'Impossible de récupérer le titre du jeu de données',
}, },
matomo: {
getViews: 'Impossible de récupérer le nombre de vues',
},
}; };
...@@ -18,4 +18,7 @@ export const errors = { ...@@ -18,4 +18,7 @@ export const errors = {
getDatasetChildren: 'Failed to get the dataset children', getDatasetChildren: 'Failed to get the dataset children',
getDatasetTitle: 'Failed to get the datatset title', getDatasetTitle: 'Failed to get the datatset title',
}, },
matomo: {
getViews: 'Cannot get the views count',
},
}; };
...@@ -20,19 +20,6 @@ ...@@ -20,19 +20,6 @@
</section> </section>
</app-root> </app-root>
<script type="text/javascript">
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
// _paq.push(['trackPageView']); // DELETE THIS LINE
_paq.push(['enableLinkTracking']);
(function() {
var u="//localhost:8181/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
</body> </body>
</html> </html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment