Skip to content

Commit

Permalink
feat: add matomo tracking for differents buttons (#369)
Browse files Browse the repository at this point in the history
* feat: add matomo tracking for differents buttons

* feat: add new tracker matomo buttons

* fix: test

* fix: add id to ouverture fiche
  • Loading branch information
abelkhay committed Oct 12, 2023
1 parent ee43201 commit 968d5f5
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, Optional } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { ConditionAcces, LabelNational } from '@gouvfr-anct/lieux-de-mediation-numerique';
Expand All @@ -9,6 +9,7 @@ import {
toFilterFormPresentationFromQuery
} from '../../../core/presenters';
import { labelsAutresFrom, labelNationauxFrom, strategiesTerritorialesFrom } from './affiner-recherche-form.presenter';
import { MatomoTracker } from 'ngx-matomo';

type AffinerRechercheFields = {
prise_rdv: FormControl<boolean>;
Expand Down Expand Up @@ -60,7 +61,11 @@ export class AffinerRechercheFormComponent {
['ZRR', 'ZRR (zones de revitalisation rurale)']
]);

public constructor(public route: ActivatedRoute, public readonly router: Router) {}
public constructor(
public route: ActivatedRoute,
public readonly router: Router,
@Optional() private readonly _matomoTracker?: MatomoTracker
) {}

public affinerRechercheForm: FormGroup<AffinerRechercheFields> = AFFINER_RECHERCHE_FORM(
toFilterFormPresentationFromQuery(this.route.snapshot.queryParams)
Expand All @@ -71,6 +76,7 @@ export class AffinerRechercheFormComponent {
public labelNationauxFrom = labelNationauxFrom;

public setFilterToQueryString(field: string): void {
this._matomoTracker?.trackEvent('Cartographie', 'Affiner recherche', field);
this.router.navigate([], {
queryParams: {
...this.route.snapshot.queryParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<a
class="text-decoration-none link-dark link-lieu"
[routerLink]="[lieuMediationNumerique.id, 'details']"
(click)="matomoTracking(lieuMediationNumerique.id)"
[relativeTo]="route.parent"
queryParamsHandling="preserve"
(mouseover)="enableHover.emit(lieuMediationNumerique.id)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, Output } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, Optional, Output } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ConditionAcces, LabelNational } from '@gouvfr-anct/lieux-de-mediation-numerique';
import { ASSETS_TOKEN, AssetsConfiguration } from '../../../../../root';
import { LieuMediationNumeriqueListItemPresentation } from '../../../presenters';
import { MatomoTracker } from 'ngx-matomo';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -24,10 +25,15 @@ export class LieuMediationNumeriqueListItemComponent {

public constructor(
@Inject(ASSETS_TOKEN) public assetsConfiguration: AssetsConfiguration,
public readonly route: ActivatedRoute
public readonly route: ActivatedRoute,
@Optional() private readonly _matomoTracker?: MatomoTracker
) {}

public dateIsValide(dateMaj: Date): boolean {
return dateMaj > new Date('1970-01-01');
}

public matomoTracking(lieuID: string): void {
this._matomoTracker?.trackEvent('Fiches', 'Début', `Ouverture de fiches - ${lieuID}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h3 class="card-title text-primary">
class="navbar-btn pb-1 pt-0 mt-1"
[attr.aria-controls]="aideOffcanvas.id"
[class.active]="aideOffcanvas.expanded$ | async"
(click)="aideOffcanvas.toggle($event); affinerRechercheOffcanvas.close()">
(click)="aideOffcanvas.toggle($event); affinerRechercheOffcanvas.close(); matomoAideButtonTracking()">
<i
class="ri-2x"
[ngClass]="(aideOffcanvas.expanded$ | async) ? 'ri-close-circle-line text-primary' : 'ri-question-line'"></i>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Inject, ViewChild } from '@angular/core';
import { ChangeDetectionStrategy, Component, Inject, Optional, ViewChild } from '@angular/core';
import { ActivatedRoute, ParamMap, Router, RouterOutlet } from '@angular/router';
import { BehaviorSubject, Observable, of, Subject, tap, withLatestFrom } from 'rxjs';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -33,6 +33,7 @@ import {
shouldNavigateToListPage
} from '../../presenters';
import { cartographieLayoutProviders } from './cartographie.layout.providers';
import { MatomoTracker } from 'ngx-matomo';

const filteredByDepartementIfExist = (
departement: DepartementPresentation | undefined,
Expand Down Expand Up @@ -161,7 +162,8 @@ export class CartographieLayout {
public readonly markersPresenter: MarkersPresenter,
@Inject(ASSETS_TOKEN) public readonly assetsConfiguration: AssetsConfiguration,
@Inject(ZOOM_LEVEL_TOKEN)
private readonly _zoomLevel: ZoomLevelConfiguration
private readonly _zoomLevel: ZoomLevelConfiguration,
@Optional() private readonly _matomoTracker?: MatomoTracker
) {}

public onShowLieuxInDepartement(departement: TerritoirePresentation): void {
Expand Down Expand Up @@ -251,4 +253,8 @@ export class CartographieLayout {
public toggleMapForSmallDevices(): void {
this._showMapForSmallDevices$.next(!this._showMapForSmallDevices$.value);
}

public matomoAideButtonTracking(): void {
this._matomoTracker?.trackEvent('Cartograhie', 'Sidebar', 'Bouton aide');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[ngClass]="'btn-' + buttonStyle"
[class.disabled]="lieuxMediationNumeriqueCount === 0"
[routerLink]="['/', 'cartographie']"
queryParamsHandling="preserve">
queryParamsHandling="preserve"
(click)="matomoTracking()">
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</a>
<a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DisplayOnMapLinkComponent } from './display-on-map-link.component';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';

describe('DisplayOnMapLinkComponent', (): void => {
beforeEach(async (): Promise<void> => {
await TestBed.configureTestingModule({
declarations: [DisplayOnMapLinkComponent]
declarations: [DisplayOnMapLinkComponent],
providers: [
{
provide: ActivatedRoute,
useValue: {
queryParams: of([])
}
}
]
})
.compileComponents()
.catch((): void => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, Optional } from '@angular/core';
import { ActivatedFeatureConfiguration } from '../../../../root';
import { HttpParams } from '@angular/common/http';
import { MatomoTracker } from 'ngx-matomo';
import { ActivatedRoute } from '@angular/router';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -16,7 +18,20 @@ export class DisplayOnMapLinkComponent {

@Input() public buttonStyle: 'primary' | 'secondary' = 'secondary';

public constructor(private route: ActivatedRoute, @Optional() private readonly _matomoTracker?: MatomoTracker) {}

public toQueryString(fromObject: {} = {}): string {
return new HttpParams({ fromObject }).toString();
}

public matomoTracking(): void {
const filtersKeys = this.route.snapshot.queryParams;
Object.keys(filtersKeys).map((key) =>
this._matomoTracker?.trackEvent(
'Parcours orientation',
'filtres',
`${key} - ${Array.isArray(filtersKeys[key]) ? filtersKeys[key].join(', ') : filtersKeys[key]}`
)
);
}
}

0 comments on commit 968d5f5

Please sign in to comment.