| | const Amplify = window.aws_amplify.Amplify |
| | const Analytics = Amplify.Analytics |
| | const KinesisFirehoseProvider = window.aws_amplify.AWSKinesisFirehoseProvider |
| |
|
| | const awsconfig = { |
| | "aws_project_region": "eu-west-1", |
| | "aws_cognito_identity_pool_id": "eu-west-1:3df3caec-4bb6-4891-b154-ee940c8264b8", |
| | "aws_cognito_region": "eu-west-1", |
| | "aws_kinesis_firehose_stream_name": "ClickStreamKinesisFirehose-OGX7PQdrynUo", |
| | }; |
| |
|
| | const RUNTIME = "python" |
| | const BASE_ORIGIN = "docs.powertools.aws.dev" |
| |
|
| | function copyToClipboard(e) { |
| | e.preventDefault() |
| | navigator.clipboard.writeText(e.target.textContent) |
| | alert$.next("Copied to clipboard") |
| | } |
| |
|
| | function enableSearchOnBlurElement() { |
| | if (document.location.hostname != BASE_ORIGIN) return |
| | |
| | document.addEventListener("DOMContentLoaded", function () { |
| | recordPageView({ |
| | prevLocation: document.referrer |
| | }) |
| | if (document.forms.search) { |
| | let query = document.forms.search.query |
| | query.addEventListener("blur", function () { |
| | |
| | |
| | if (this.value) { |
| | let path = document.location.pathname; |
| | console.info(`Search value: ${this.value}`) |
| | recordPageView({ |
| | searchPattern: this.value |
| | }) |
| | } |
| | }) |
| | } |
| | }) |
| |
|
| | |
| | window.onpopstate = function (event) { |
| | recordPageView({ |
| | prevLocation: document.referrer |
| | }) |
| | }; |
| | } |
| |
|
| | function enableClipboardElements() { |
| | let copyElements = document.querySelectorAll('.copyMe'); |
| | copyElements.forEach(element => { |
| | element.addEventListener('click', copyToClipboard); |
| | }) |
| | } |
| |
|
| | const attachListeners = () => { |
| | enableSearchOnBlurElement() |
| | enableClipboardElements() |
| | } |
| |
|
| | const init = () => { |
| | Analytics.addPluggable(new KinesisFirehoseProvider()) |
| | Amplify.configure(awsconfig); |
| |
|
| | Analytics.configure({ |
| | AWSKinesisFirehose: { |
| | region: awsconfig.aws_project_region |
| | } |
| | }) |
| |
|
| | attachListeners() |
| | } |
| |
|
| | const recordPageView = ({prevLocation, searchPattern}) => { |
| | Analytics.record({ |
| | data: { |
| | |
| | url: searchPattern ? null : window.location.href, |
| | section: searchPattern ? null : location.pathname, |
| | previous: prevLocation || null, |
| | search: searchPattern || null, |
| | language: RUNTIME |
| | }, |
| | streamName: awsconfig.aws_kinesis_firehose_stream_name |
| | }, 'AWSKinesisFirehose') |
| | } |
| |
|
| | init() |
| |
|