Skip to content

Commit

Permalink
Add card source indications
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed May 5, 2024
1 parent ca89dc1 commit 044fb45
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion projects/srm/src/app/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AnalyticsService {
}
}

cardEvent(card: Card, params: SearchParams | null, index: number, select=false) {
cardEvent(card: Card, params: SearchParams | null, index: number, select: boolean, from: string|null=null) {
console.log('EVENT card', card);
if (select) {
this.gtag({
Expand Down Expand Up @@ -157,6 +157,8 @@ export class AnalyticsService {
},
...eventParams
});

this.interactionEvent('card', from || 'unknown', undefined, params);
}
}

Expand Down
1 change: 1 addition & 0 deletions projects/srm/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class AppComponent {
cleanUrl(url: string) {
const parsed = new URL(url, window.location.href);
parsed.searchParams.delete('li');
parsed.searchParams.delete('from');
parsed.searchParams.delete('gtm_debug');
parsed.hash = '';
const ret = parsed.toString().slice(window.location.origin.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export class CardBranchServicesComponent implements OnInit {

navigateToCard(event: Event, card: Card) {
event.preventDefault();
this.router.navigate(['../..', 'c', card.card_id], {relativeTo: this.route, queryParamsHandling: 'merge'});
this.router.navigate(['../..', 'c', card.card_id], {relativeTo: this.route, queryParamsHandling: 'merge', queryParams: {from: 'branch-services'}});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ export class CardContainerComponent implements OnInit, OnChanges {
let index = 0;
if (li) {
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, index);
const from = this.route.snapshot.queryParams['from'];
if (from || li) {
this.router.navigate([], {relativeTo: this.route, queryParams: {from: null}, queryParamsHandling: 'merge', replaceUrl: true, preserveFragment: true});
}
this.analytics.cardEvent(card, this.searchParams, index, false, from);
});
})
).subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class='scrollable'>
@for (card of cards; track card.card_id) {
<a [interactionEvent]='"popup-card-click"' [interactionEventWhere]='"map-popup-stable"'
[routerLink]='cardRouter.route(card)' [queryParamsHandling]='"merge"'>
[routerLink]='cardRouter.route(card)' [queryParamsHandling]='"merge"' [queryParams]='{from: "map-popup-single-branch"}'>
<app-result-card [card]='card' [stacked]='true' [smaller]='true' [bold]='true'></app-result-card>
</a>
}
Expand All @@ -22,7 +22,7 @@
</div>
@for (card of branch.cards; track card.card_id) {
<a [interactionEvent]='"popup-card-click"' [interactionEventWhere]='"map-popup-stable"'
[routerLink]='cardRouter.route(card)' [queryParamsHandling]='"merge"'
[routerLink]='cardRouter.route(card)' [queryParamsHandling]='"merge"' [queryParams]='{from: "map-popup-multi-branch"}'
>
<app-result-card [card]='card' [stacked]='true' [smaller]='true' [bold]='true'></app-result-card>
</a>
Expand Down
5 changes: 4 additions & 1 deletion projects/srm/src/app/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,21 @@ export class MapComponent implements OnChanges, AfterViewInit, OnDestroy {
})
).subscribe((newCardId: string | null) => {
const route = [];
const queryParams: any = {};
let dontRoute = false;
if (this.searchParams?.ac_query) {
route.push('s', this.searchParams?.ac_query);
}
if (newCardId && this.layout.desktop()) {
route.push('c', newCardId);
queryParams.from = 'map-click';
} else {
if (this.layout.mobile()) {
if (this.cardId && (!this.pointId || this.pointId === props.point_id)) {
route.push('c', this.cardId, 'p', props.point_id);
} else if (this.pointId === props.point_id && this.markerProps?.card_id) {
route.push('c', this.markerProps.card_id);
queryParams.from = 'map-click';
} else {
route.push('p', props.point_id);
}
Expand All @@ -393,7 +396,7 @@ export class MapComponent implements OnChanges, AfterViewInit, OnDestroy {
}
if (!dontRoute) {
route[0] = '/' + route[0];
this.router.navigate(route, {queryParamsHandling: 'preserve'});
this.router.navigate(route, {queryParamsHandling: 'merge', queryParams});
}
});
// this.points.next(props as SRMPoint);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@for (card of cards; track card.card_id; let i = $index) {
<a class='card'
[class.last-non-hidden]='i === cards.length - 1 && hidden_'
[routerLink]='routerLink(card)' queryParamsHandling='preserve'
[routerLink]='routerLink(card)' queryParamsHandling='merge'
[queryParams]='{from: "point-view"}'
[attr.data-card]='card | json' [style.zIndex]='200 - i'
>
<app-result-card [card]='card' [compact]='true'></app-result-card>
Expand All @@ -19,7 +20,10 @@
}
@if (triggerClicked_) {
@for (card of hiddenCards; track card.card_id; let i = $index) {
<a class='card' [routerLink]='routerLink(card)' [class.hidden]='hidden_' queryParamsHandling='preserve'
<a class='card'
[routerLink]='routerLink(card)'
[queryParams]='{from: "point-view"}'
[class.hidden]='hidden_' queryParamsHandling='merge'
[attr.data-card]='card | json' [style.zIndex]='100 - i'
>
<app-result-card [card]='card' [compact]='true'></app-result-card>
Expand Down
4 changes: 2 additions & 2 deletions projects/srm/src/app/result-stack/result-stack.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<a (mouseover)='hover.next(result)'
[attr.aria-label]='ariaLabel(result)'
(activated)='selectedItem($event, result)'
(activated)='selectedItem($event, result, "search-result-main")'
class='card' [class.collapsible]='collapsible' clickOnReturn
[href]='"/c/" + result.card_id'
>
Expand All @@ -18,7 +18,7 @@
@for (extra of result.collapse_hits || []; track extra.card_id; let i = $index) {
<a (mouseover)='hover.next(extra)'
[attr.aria-label]='ariaLabel(extra)'
(activated)='selectedItem($event, result, extra)'
(activated)='selectedItem($event, result, "search-result-extras", extra)'
[href]='"/c/" + extra.card_id'
[class.national]='extra.national_service'
[style.display]='i + 1 < showCount ? "block" : "none"'
Expand Down
4 changes: 2 additions & 2 deletions projects/srm/src/app/result-stack/result-stack.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ export class ResultStackComponent implements OnInit {
return ret;
}

selectedItem(event: Event, card: Card, extra?: any) {
selectedItem(event: Event, card: Card, from: string, extra?: any) {
event.preventDefault();
let card_ = card;
if (extra) {
card_ = Object.assign({}, card, extra);
}
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 });
this.router.navigate(['c', card_.card_id], { relativeTo: this.route, queryParams: {li: this.index, from}, queryParamsHandling: 'merge', preserveFragment: true });
return false;
}
}
1 change: 1 addition & 0 deletions projects/srm/src/app/search/search-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class SearchConfig {
display,
query: null,
direct: true,
linkParams: {from: 'search-autocomplete-direct'},
};
});
this.results_ = null;
Expand Down

0 comments on commit 044fb45

Please sign in to comment.