Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 38x 38x 38x 38x 38x 38x 38x 1x 1x 1x 1x 1x 1x 1x 38x 38x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 38x 38x 38x 38x 38x | import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { UserClass } from '@classes/user.class';
import { environment } from '@environments/environment';
declare let window: any;
@Injectable({
providedIn: 'root',
})
export class GtmService {
private http = inject(HttpClient);
url: string = environment.apiUrl;
register(user: UserClass): void {
this._send('new', user);
}
login(user: UserClass, headers: HttpHeaders): void {
this._getUserItineraryIds(headers)
.then((ids) => {
if (ids.length) {
this._send('returning', user, ids.join(', '));
} else {
this._send('new', user);
}
})
.catch((e) => {
console.error(e);
});
}
private _getUserItineraryIds(headers: HttpHeaders): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
this.http.get<any>(this.url + '/itineraries', { headers }).subscribe(
(response) => {
if (response.data.length) {
resolve(response.data.map(({ id }: { id: string }) => id));
}
resolve([]);
},
(error) => {
reject(error);
},
);
});
}
_send(type: string, user: UserClass, itineraryId: string = '') {
window.dataLayer.push({
event: 'form_submit',
itineraryId,
clientEmail: user.getEmail(),
clientName: user.getName(),
userId: user.getId(),
userType: type,
});
}
successfulPlannedTrip(user: UserClass): void {
const firstTry = sessionStorage.getItem('firstTry') === null;
if (firstTry) {
sessionStorage.setItem('firstTry', 'false');
}
const isNewCustomer = sessionStorage.getItem('newCustomer')?.toString() === 'true';
console.log('GTM Service: successfulPlannedTrip', {
userEmail: user.getEmail(),
userName: user.getName(),
userId: user.getId(),
newCustomer: isNewCustomer,
firstTry: firstTry,
});
window.dataLayer.push({
event: 'successful_planned_trip',
clientEmail: user.getEmail(),
clientName: user.getName(),
userId: user.getId(),
newCustomer: isNewCustomer.toString(), // 'true' or 'false'
firstTry: firstTry.toString(), // 'true' or 'false'
});
}
}
|