|
1 | | -const Amplify = window.aws_amplify.Amplify |
2 | | -const Analytics = Amplify.Analytics |
3 | | -const KinesisFirehoseProvider = window.aws_amplify.AWSKinesisFirehoseProvider |
| 1 | +const Amplify = window.aws_amplify.Amplify; |
| 2 | +const Analytics = Amplify.Analytics; |
| 3 | +const KinesisFirehoseProvider = window.aws_amplify.AWSKinesisFirehoseProvider; |
4 | 4 |
|
5 | 5 | const awsconfig = { |
6 | | - "aws_project_region": "eu-west-1", |
7 | | - "aws_cognito_identity_pool_id": "eu-west-1:3df3caec-4bb6-4891-b154-ee940c8264b8", |
8 | | - "aws_cognito_region": "eu-west-1", |
9 | | - "aws_kinesis_firehose_stream_name": "ClickStreamKinesisFirehose-OGX7PQdrynUo", |
| 6 | + aws_project_region: 'eu-west-1', |
| 7 | + aws_cognito_identity_pool_id: |
| 8 | + 'eu-west-1:3df3caec-4bb6-4891-b154-ee940c8264b8', |
| 9 | + aws_cognito_region: 'eu-west-1', |
| 10 | + aws_kinesis_firehose_stream_name: 'ClickStreamKinesisFirehose-OGX7PQdrynUo', |
10 | 11 | }; |
11 | 12 |
|
12 | | -const RUNTIME = "typescript" |
13 | | -const BASE_ORIGIN = "docs.powertools.aws.dev" |
| 13 | +const RUNTIME = 'typescript'; |
| 14 | +const BASE_ORIGIN = 'docs.powertools.aws.dev'; |
14 | 15 |
|
15 | 16 | function copyToClipboard(e) { |
16 | | - e.preventDefault() |
17 | | - navigator.clipboard.writeText(e.target.textContent) |
18 | | - alert$.next("Copied to clipboard") |
| 17 | + e.preventDefault(); |
| 18 | + navigator.clipboard.writeText(e.target.textContent); |
| 19 | + alert$.next('Copied to clipboard'); |
19 | 20 | } |
20 | 21 |
|
21 | 22 | function enableSearchOnBlurElement() { |
22 | | - if (document.location.hostname != BASE_ORIGIN) return // prevent unnecessary data |
23 | | - /* Register handler to log search on blur */ |
24 | | - document.addEventListener("DOMContentLoaded", function () { |
25 | | - recordPageView({ |
26 | | - prevLocation: document.referrer |
27 | | - }) |
28 | | - if (document.forms.search) { |
29 | | - let query = document.forms.search.query |
30 | | - query.addEventListener("blur", function () { |
31 | | - // If Search result is ever actionable |
32 | | - // we should populate `value` |
33 | | - if (this.value) { |
34 | | - let path = document.location.pathname; |
35 | | - console.info(`Search value: ${this.value}`) |
36 | | - recordPageView({ |
37 | | - searchPattern: this.value |
38 | | - }) |
39 | | - } |
40 | | - }) |
41 | | - } |
42 | | - }) |
| 23 | + if (document.location.hostname !== BASE_ORIGIN) return; // prevent unnecessary data |
| 24 | + /* Register handler to log search on blur */ |
| 25 | + document.addEventListener('DOMContentLoaded', () => { |
| 26 | + recordPageView({ |
| 27 | + prevLocation: document.referrer, |
| 28 | + }); |
| 29 | + if (document.forms.search) { |
| 30 | + const query = document.forms.search.query; |
| 31 | + query.addEventListener('blur', function () { |
| 32 | + // If Search result is ever actionable |
| 33 | + // we should populate `value` |
| 34 | + if (this.value) { |
| 35 | + console.info(`Search value: ${this.value}`); |
| 36 | + recordPageView({ |
| 37 | + searchPattern: this.value, |
| 38 | + }); |
| 39 | + } |
| 40 | + }); |
| 41 | + } |
| 42 | + }); |
43 | 43 |
|
44 | | - // Register handler for page sections when browser history is changed |
45 | | - window.onpopstate = function (event) { |
46 | | - recordPageView({ |
47 | | - prevLocation: document.referrer |
48 | | - }) |
49 | | - }; |
| 44 | + // Register handler for page sections when browser history is changed |
| 45 | + window.onpopstate = () => { |
| 46 | + recordPageView({ |
| 47 | + prevLocation: document.referrer, |
| 48 | + }); |
| 49 | + }; |
50 | 50 | } |
51 | 51 |
|
52 | 52 | function enableClipboardElements() { |
53 | | - let copyElements = document.querySelectorAll('.copyMe'); |
54 | | - copyElements.forEach(element => { |
55 | | - element.addEventListener('click', copyToClipboard); |
56 | | - }) |
| 53 | + const copyElements = document.querySelectorAll('.copyMe'); |
| 54 | + copyElements.forEach((element) => { |
| 55 | + element.addEventListener('click', copyToClipboard); |
| 56 | + }); |
57 | 57 | } |
58 | 58 |
|
59 | 59 | const attachListeners = () => { |
60 | | - enableSearchOnBlurElement() |
61 | | - enableClipboardElements() |
62 | | -} |
| 60 | + enableSearchOnBlurElement(); |
| 61 | + enableClipboardElements(); |
| 62 | +}; |
63 | 63 |
|
64 | 64 | const init = () => { |
65 | | - Analytics.addPluggable(new KinesisFirehoseProvider()) |
66 | | - Amplify.configure(awsconfig); |
| 65 | + Analytics.addPluggable(new KinesisFirehoseProvider()); |
| 66 | + Amplify.configure(awsconfig); |
67 | 67 |
|
68 | | - Analytics.configure({ |
69 | | - AWSKinesisFirehose: { |
70 | | - region: awsconfig.aws_project_region |
71 | | - } |
72 | | - }) |
| 68 | + Analytics.configure({ |
| 69 | + AWSKinesisFirehose: { |
| 70 | + region: awsconfig.aws_project_region, |
| 71 | + }, |
| 72 | + }); |
73 | 73 |
|
74 | | - attachListeners() |
75 | | -} |
| 74 | + attachListeners(); |
| 75 | +}; |
76 | 76 |
|
77 | | -const recordPageView = ({prevLocation, searchPattern}) => { |
78 | | - Analytics.record({ |
79 | | - data: { |
80 | | - // Do not count page view for search |
81 | | - url: searchPattern ? null : window.location.href, |
82 | | - section: searchPattern ? null : location.pathname, |
83 | | - previous: prevLocation || null, |
84 | | - search: searchPattern || null, |
85 | | - language: RUNTIME |
86 | | - }, |
87 | | - streamName: awsconfig.aws_kinesis_firehose_stream_name |
88 | | - }, 'AWSKinesisFirehose') |
89 | | -} |
| 77 | +const recordPageView = ({ prevLocation, searchPattern }) => { |
| 78 | + Analytics.record( |
| 79 | + { |
| 80 | + data: { |
| 81 | + // Do not count page view for search |
| 82 | + url: searchPattern ? null : window.location.href, |
| 83 | + section: searchPattern ? null : location.pathname, |
| 84 | + previous: prevLocation || null, |
| 85 | + search: searchPattern || null, |
| 86 | + language: RUNTIME, |
| 87 | + }, |
| 88 | + streamName: awsconfig.aws_kinesis_firehose_stream_name, |
| 89 | + }, |
| 90 | + 'AWSKinesisFirehose' |
| 91 | + ); |
| 92 | +}; |
90 | 93 |
|
91 | | -init() |
| 94 | +init(); |
0 commit comments