Skip to content

Commit

Permalink
Send landing_page always
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Mar 31, 2024
1 parent 29cd46a commit 13593c9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
26 changes: 20 additions & 6 deletions projects/srm/src/app/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,24 @@ declare const window: {
providedIn: 'root'
})
export class AnalyticsService {
landingPage = true;
referrer: string | null = '';

constructor(private platform: PlatformService) { }
constructor(private platform: PlatformService) {
window.gtag(['config', 'G-SSW46Z8STP', {'send_page_view': false}]);
this.referrer = document.referrer;
}

pageView(url: string) {
window.gtag({
event: 'srm:page_view',
page_path: url,
landing_page: this.landingPage ? 'yes' : 'no',
doc_referrer: this.referrer,
});
this.landingPage = false;
this.referrer = null;
}

cardToItem(card: Card, idx: number, item_list_name?: string | null): any {
const address = card.address_parts ?
Expand Down Expand Up @@ -68,17 +84,16 @@ export class AnalyticsService {
}


searchEvent(params: SearchParams, isLandingPage: boolean, numTotalResults: number, items: Card[], offset=0) {
searchEvent(params: SearchParams, numTotalResults: number, items: Card[], offset=0) {
const title = params.original_query;
console.log('EVENT search', title, isLandingPage, numTotalResults);
console.log('EVENT search', title, numTotalResults);
if (title && this.platform.browser() && window.gtag) {
const responseCount = (params.filter_responses || []).length;
const eventParams = {
search_term: title,
filter_count: params.allTaxonomyIds.filter(x => !!x).length - responseCount,
filter_responses_count: responseCount,
filter_response_categories_count: (params.filter_response_categories || []).length,
landing_page: isLandingPage ? 'yes' : 'no',
search_structured: !!params.query ? 'no' : 'yes',
num_results_total: numTotalResults,
};
Expand All @@ -101,7 +116,7 @@ export class AnalyticsService {
}
}

cardEvent(card: Card, params: SearchParams | null, isLandingPage: boolean, index: number, select=false) {
cardEvent(card: Card, params: SearchParams | null, index: number, select=false) {
console.log('EVENT card', card);
if (this.platform.browser() && window.gtag) {
if (select) {
Expand All @@ -117,7 +132,6 @@ export class AnalyticsService {
card_id: card.card_id,
card_name: card.service_name,
card_org: card.organization_id,
landing_page: isLandingPage ? 'yes' : 'no',
search_term: params?.original_query,
search_structured: !!params?.query ? 'no' : 'yes',
};
Expand Down
15 changes: 5 additions & 10 deletions projects/srm/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs';
import { environment } from '../environments/environment';
import { PlatformService } from './platform.service';
import { marked } from 'marked';
import { AnalyticsService } from './analytics.service';

declare const window: any;

Expand All @@ -19,9 +20,10 @@ export class AppComponent {
// private analytics: AnalyticsService,
private router: Router,
private platform: PlatformService,
private seo: SeoSocialShareService) {
private seo: SeoSocialShareService,
private analytics: AnalyticsService,
) {
platform.browser(() => {
let initial = true;
if (environment.gaTag) {
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
Expand All @@ -30,15 +32,8 @@ export class AppComponent {
distinctUntilChanged()
).subscribe((urlAfterRedirects) => {
platform.browser(() => {
if (initial && window.gtag) {
window.gtag(['config', 'G-SSW46Z8STP', {'send_page_view': false}]);
initial = false;
}
console.log('PAGE_VIEW', urlAfterRedirects);
window.gtag && window.gtag({
event: 'srm:page_view',
page_path: urlAfterRedirects
});
analytics.pageView(urlAfterRedirects);
})
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class CardContainerComponent implements OnInit, OnChanges {

@Input() cardId = '';
@Input() searchParams: SearchParams;
@Input() isLandingPage: boolean;
@Output() center = new EventEmitter<LngLatLike>();
@Output() size = new EventEmitter<number>();
@Output() zoomout = new EventEmitter<ViewPort>();
Expand Down Expand Up @@ -144,7 +143,7 @@ export class CardContainerComponent implements OnInit, OnChanges {
index = parseInt(li, 10);
this.router.navigate([], {relativeTo: this.route, queryParams: {li: null}, queryParamsHandling: 'merge', replaceUrl: true, preserveFragment: true});
}
this.analytics.cardEvent(card, this.searchParams, this.isLandingPage, index);
this.analytics.cardEvent(card, this.searchParams, index);
});
})
).subscribe();
Expand Down
3 changes: 0 additions & 3 deletions projects/srm/src/app/page/page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
[searchParams]='searchParams'
[active]="stage === 'search-results'"
[didYouMean]='didYouMean'
[isLandingPage]='isLandingPage'
[searchState]='searchState'
(zoomout)='zoomOutMap($event)'
(visibleCount)='visibleCount = $event'
Expand All @@ -75,7 +74,6 @@
*ngIf='stage === "card"'
[cardId]='card'
[searchParams]='searchParams'
[isLandingPage]='isLandingPage'
(center)='centerMap($event)'
(size)='branchSize = $event'
(zoomout)='zoomOutMap($event)'
Expand All @@ -87,7 +85,6 @@
[searchParams]='searchParams'
[cardId]='card'
[visibleCount]='visibleCount'
[landingPage]='isLandingPage'
(open)='showLandingPageOverlay = $event'
></app-landing-page-overlay>
</div>
Expand Down
4 changes: 0 additions & 4 deletions projects/srm/src/app/page/page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export class PageComponent implements OnInit, AfterViewInit, OnDestroy {
visibleCount = 0;

showLandingPageOverlay = false;
isLandingPage = true;

didYouMean: {display: string, link: string} | null = null;
searchState: SearchState;
Expand Down Expand Up @@ -364,9 +363,6 @@ export class PageComponent implements OnInit, AfterViewInit, OnDestroy {
timer(100).subscribe(() => {
this.setPadding();
});
if (prevStage !== '') {
this.isLandingPage = false;
}
this.map?.setPopup(false, null);
});
route.queryParams.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class ResultStackComponent implements OnInit {
if (extra) {
card_ = Object.assign({}, card, extra);
}
this.analytics.cardEvent(card_, this.searchParams, false, this.index, true);
this.analytics.cardEvent(card_, this.searchParams, this.index, true);
this.router.navigate(['c', card_.card_id], { relativeTo: this.route, queryParams: {li: this.index}, queryParamsHandling: 'merge', preserveFragment: true });
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class SearchResultsComponent implements OnInit, OnChanges, AfterViewInit
@Input() searchParams: SearchParams;
@Input() active = false;
@Input() didYouMean: {display: string, link: string} | null = null;
@Input() isLandingPage = true;
@Input() searchState: SearchState;
@Output() zoomout = new EventEmitter<ViewPort>();
@Output() nationalCount = new EventEmitter<number>();
Expand Down Expand Up @@ -172,7 +171,7 @@ export class SearchResultsComponent implements OnInit, OnChanges, AfterViewInit
return a.params.original_query === b.params.original_query && a.params.ac_query === b.params.ac_query && a.offset === b.offset;
}),
tap((item) => {
this.analytics.searchEvent(item.params, this.isLandingPage, item.totalCount, item.items, item.offset);
this.analytics.searchEvent(item.params, item.totalCount, item.items, item.offset);
})
).subscribe();
}
Expand Down
2 changes: 0 additions & 2 deletions projects/srm/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<link rel="icon" type="image/x-icon" href="favicon.svg">
<script>
function gtag(i){console.log('GTAG-DBG', i)};
var pushState = history.pushState; history.pushState = function(state) { console.log('PSTATE', state); return pushState.apply(history, arguments);};
var replState = history.replaceState; history.replaceState = function(state) { console.log('RSTATE', state); return replState.apply(history, arguments);};
</script>
</head>
<body>
Expand Down

0 comments on commit 13593c9

Please sign in to comment.