All files / app app.component.ts

88.44% Statements 176/199
96.15% Branches 25/26
60% Functions 3/5
88.44% Lines 176/199

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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 2001x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x                         1x 1x 5x 5x 5x             5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 2x 2x 5x 5x 2x 2x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x  
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, PLATFORM_ID, inject } from '@angular/core';
import { ActivatedRoute, RouterOutlet } from '@angular/router';
import { CookiesElementComponent } from '@elements/cookies-element/cookies-element.component';
import { AuthService } from '@services/auth.service';
import { SeoService } from '@services/seo.service';
import { UTMTrackerService } from '@services/utm-tracker.service';
import { CookieService } from 'ngx-cookie-service';
import { ChatWidgetComponent } from './elements/chat-widget/chat-widget.component';
 
@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.scss'],
	imports: [RouterOutlet, CookiesElementComponent, ChatWidgetComponent],
})
export class AppComponent implements OnInit {
	private cookieService = inject(CookieService);
	private platformId = inject(PLATFORM_ID);
	private seoService = inject(SeoService);
	private utmTracker = inject(UTMTrackerService);
	private authService = inject(AuthService);
	route = inject(ActivatedRoute);
 
	isBrowser: boolean;
 
	title = 'GoRealEurope';
 
	// UTMs
	utm_medium!: string;
	utm_email!: string;
	utm_source!: string;
	utm_campaign!: string;
	utm_term!: string;
	utm_content!: string;
 
	// extras
	lead_form_type!: string;
	page_url!: string;
	marketing_trip_name!: string;
 
	// google ads (NEW)
	hsa_acc!: string;
	hsa_cam!: string;
	hsa_grp!: string;
	hsa_ad!: string;
	hsa_src!: string;
	hsa_tgt!: string;
	hsa_kw!: string;
	hsa_mt!: string;
	hsa_net!: string;
	hsa_ver!: string;
 
	// special
	cjevent!: string;
	gre_ta!: string;
 
	showCookieBar = false;
 
	constructor() {
		this.isBrowser = isPlatformBrowser(this.platformId);
	}
 
	onActivate() {
		if (isPlatformBrowser(this.platformId)) {
			window.scroll(0, 0);
		}
	}
 
	onCookieBarClose(shouldHide: boolean) {
		if (shouldHide && this.isBrowser) {
			window.localStorage.setItem('cookie_bar', 'done');
			this.showCookieBar = false;
		}
	}
 
	getSubdomain(): string | null {
		if (typeof window === 'undefined') return null;

		const host = window.location.hostname;
		// byondtravel.staging.gorealtravel.com

		const parts = host.split('.');

		// handle localhost or edge cases
		if (parts.length < 3) return null;

		return parts[0]; // "byondtravel"
	}
 
	ngOnInit(): void {
		this.authService.verifySession().subscribe();
 
		setTimeout(() => {
			if (this.isBrowser) {
				const script = document.createElement('script');
				script.src = '//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js';
				script.defer = true;
				document.head.appendChild(script);
			}
		}, 1000);
 
		if (this.isBrowser) {
			this.showCookieBar = localStorage.getItem('cookie_bar') !== 'done';
		}
 
		this.utmTracker.initOnFirstPage();
 
		// =========================
		// QUERY PARAMS TRACKING
		// =========================
		this.route.queryParams.subscribe((params) => {
			// SPECIAL
			this.cjevent = params['cjevent'];
			this.gre_ta = params['gre_ta'];
 
			// UTM
			this.utm_medium = params['utm_medium'];
			this.utm_email = params['utm_email'];
			this.utm_source = Array.isArray(params['utm_source']) ? params['utm_source'][0] : params['utm_source'];
 
			this.utm_campaign = params['utm_campaign'];
			this.utm_term = params['utm_term'];
			this.utm_content = params['utm_content'];
 
			// EXTRA
			this.lead_form_type = params['lead_form_type'];
			this.page_url = params['page_url'];
			this.marketing_trip_name = params['marketing_trip_name'];
 
			// =========================
			// GOOGLE ADS (hsa_* NEW)
			// =========================
			this.hsa_acc = params['hsa_acc'];
			this.hsa_cam = params['hsa_cam'];
			this.hsa_grp = params['hsa_grp'];
			this.hsa_ad = params['hsa_ad'];
			this.hsa_src = params['hsa_src'];
			this.hsa_tgt = params['hsa_tgt'];
			this.hsa_kw = params['hsa_kw'];
			this.hsa_mt = params['hsa_mt'];
			this.hsa_net = params['hsa_net'];
			this.hsa_ver = params['hsa_ver'];
 
			// =========================
			// CLEAN OLD COOKIES
			// =========================
			this.cookieService.delete('_utm_params', '/');
			this.cookieService.delete('_cjevent', '/');
			this.cookieService.delete('_gre_ta', '/');
 
			// =========================
			// SET BASIC COOKIES
			// =========================
			if (this.cjevent) {
				this.cookieService.set('_cjevent', this.cjevent, 120, '/');
			}
 
			if (this.gre_ta) {
				this.cookieService.set('_gre_ta', this.gre_ta, 120, '/');
			}
 
			// =========================
			// BUILD FINAL PARAM OBJECT
			// =========================
			const source: any = {};
 
			// UTM
			if (this.utm_medium) source.utm_medium = this.utm_medium;
			if (this.utm_email) source.utm_email = this.utm_email;
			if (this.utm_source) source.utm_source = this.utm_source;
			if (this.utm_campaign) source.utm_campaign = this.utm_campaign;
			if (this.utm_term) source.utm_term = this.utm_term;
			if (this.utm_content) source.utm_content = this.utm_content;
 
			// extras
			if (this.lead_form_type) source.lead_form_type = this.lead_form_type;
			if (this.page_url) source.page_url = this.page_url;
			if (this.marketing_trip_name) source.marketing_trip_name = this.marketing_trip_name;
 
			// google ads (RAW - NO FIRST/NO CURRENT LOGIC)
			if (this.hsa_acc) source.hsa_acc = this.hsa_acc;
			if (this.hsa_cam) source.hsa_cam = this.hsa_cam;
			if (this.hsa_grp) source.hsa_grp = this.hsa_grp;
			if (this.hsa_ad) source.hsa_ad = this.hsa_ad;
			if (this.hsa_src) source.hsa_src = this.hsa_src;
			if (this.hsa_tgt) source.hsa_tgt = this.hsa_tgt;
			if (this.hsa_kw) source.hsa_kw = this.hsa_kw;
			if (this.hsa_mt) source.hsa_mt = this.hsa_mt;
			if (this.hsa_net) source.hsa_net = this.hsa_net;
			if (this.hsa_ver) source.hsa_ver = this.hsa_ver;
 
			// =========================
			// STORE FINAL COOKIE
			// =========================
			this.cookieService.set('_utm_params', JSON.stringify(source), 120, '/');
		});
	}
}