Skip to content

Commit dfe40a7

Browse files
authored
Merge pull request #2082 from hashicorp/br-events
Fathom Event Tracking
2 parents 56b07a9 + a27e601 commit dfe40a7

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

website/app/components/doc/link-with-icon/index.hbs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44
}}
55

66
{{#if @route}}
7-
<LinkTo class={{this.classNames}} @route={{@route}} @models={{this.models}} ...attributes>
7+
<LinkTo
8+
class={{this.classNames}}
9+
@route={{@route}}
10+
@models={{this.models}}
11+
...attributes
12+
{{on "click" (fn this.eventTracking.trackEvent @eventName)}}
13+
>
814
{{@label}}
915
<FlightIcon class="doc-link-with-icon__icon" @name={{@icon}} />
1016
</LinkTo>
1117
{{/if}}
1218
{{#if @href}}
13-
<a class={{this.classNames}} href={{@href}} target="_blank" rel="noopener noreferrer" ...attributes>
19+
<a
20+
class={{this.classNames}}
21+
href={{@href}}
22+
target="_blank"
23+
rel="noopener noreferrer"
24+
{{on "click" (fn this.eventTracking.trackEvent @eventName)}}
25+
...attributes
26+
>
1427
{{@label}}
1528
<FlightIcon class="doc-link-with-icon__icon" @name={{@icon}} />
1629
</a>

website/app/components/doc/link-with-icon/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*/
55

66
import Component from '@glimmer/component';
7+
import { inject as service } from '@ember/service';
78

89
export default class DocLinkWithIconComponent extends Component {
10+
@service eventTracking;
11+
912
get models() {
1013
// we need to use this trick to overcome the problem of `<LinkTo>` going beserk if we pass
1114
// a `@model` argument which is undefined (while an empty `@models` array is OK)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Service from '@ember/service';
2+
import { inject as service } from '@ember/service';
3+
import { action } from '@ember/object';
4+
5+
export default class EventService extends Service {
6+
@service fastboot;
7+
8+
@action
9+
trackEvent(eventName) {
10+
// Only attempt to do something if we are in the right environment
11+
if (!this.fastboot.isFastBoot && window.fathom && eventName) {
12+
// https://usefathom.com/docs/features/events
13+
window.fathom.trackEvent(eventName);
14+
}
15+
}
16+
}

website/app/templates/index.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@
1616
@label="Release Notes"
1717
@icon="arrow-right"
1818
@isAnimated={{true}}
19+
@eventName="Hero - Release Notes"
1920
/>
2021
<Doc::LinkWithIcon
2122
@href="https://go.hashi.co/hds-rollout"
2223
@label="Helios Roadmap"
2324
@icon="external-link"
2425
@isAnimated={{true}}
26+
@eventName="Hero - Roadmap"
2527
/>
2628
<Doc::LinkWithIcon
2729
@href="https://go.hashi.co/hds-feedback"
2830
@label="Share Feedback"
2931
@icon="external-link"
3032
@isAnimated={{true}}
33+
@eventName="Hero - Feedback"
3134
/>
3235
</div>
3336
</div>
@@ -44,6 +47,7 @@
4447
@fillParent={{true}}
4548
@isAnimated={{true}}
4649
aria-label={{concat "Explore " card.title ": " card.description}}
50+
@eventName={{concat "Card - " card.title}}
4751
/>
4852
</li>
4953
{{/each}}

0 commit comments

Comments
 (0)