|
| 1 | +<!-- |
| 2 | + Copyright (c) 2016-2021 Martin Donath <[email protected]> |
| 3 | +
|
| 4 | + Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + of this software and associated documentation files (the "Software"), to |
| 6 | + deal in the Software without restriction, including without limitation the |
| 7 | + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 | + sell copies of the Software, and to permit persons to whom the Software is |
| 9 | + furnished to do so, subject to the following conditions: |
| 10 | +
|
| 11 | + The above copyright notice and this permission notice shall be included in |
| 12 | + all copies or substantial portions of the Software. |
| 13 | +
|
| 14 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 | + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 | + IN THE SOFTWARE. |
| 21 | +--> |
| 22 | + |
| 23 | +<!-- Determine analytics property (deprecated, removed in v8) --> |
| 24 | +{% if config.google_analytics %} |
| 25 | + {% set property = config.google_analytics[0] %} |
| 26 | +{% endif %} |
| 27 | + |
| 28 | +<!-- Determine analytics property --> |
| 29 | +{% if config.extra.analytics %} |
| 30 | + {% set property = config.extra.analytics.property | d("", true) %} |
| 31 | +{% endif %} |
| 32 | + |
| 33 | +<!-- Google Analytics 4 (G-XXXXXXXXXX) --> |
| 34 | +{% if property.startswith("G-") %} |
| 35 | + <script> |
| 36 | + window.dataLayer = window.dataLayer || [] |
| 37 | + function gtag() { dataLayer.push(arguments) } |
| 38 | + |
| 39 | + /* Set up integration and send page view */ |
| 40 | + gtag("js", new Date()) |
| 41 | + gtag("config", "{{ property }}") |
| 42 | + |
| 43 | + /* Register virtual event handlers */ |
| 44 | + document.addEventListener("DOMContentLoaded", function() { |
| 45 | + |
| 46 | + /* Send page view on location change */ |
| 47 | + if (typeof location$ !== "undefined") |
| 48 | + location$.subscribe(function(url) { |
| 49 | + gtag("config", "{{ property }}", { |
| 50 | + page_path: url.pathname |
| 51 | + }) |
| 52 | + }) |
| 53 | + }) |
| 54 | + </script> |
| 55 | + <script async src="https://www.googletagmanager.com/gtag/js?id={{ property }}"> |
| 56 | + </script> |
| 57 | + |
| 58 | +<!-- Google Analytics (UA-XXXXXXXX-X) --> |
| 59 | +{% elif property.startswith("UA-") %} |
| 60 | + <script> |
| 61 | + window.ga = window.ga || function() { |
| 62 | + (ga.q = ga.q || []).push(arguments) |
| 63 | + } |
| 64 | + ga.l = +new Date() |
| 65 | + |
| 66 | + /* Set up integration and send page view */ |
| 67 | + ga("create", "{{ property }}", "auto") |
| 68 | + ga("set", "anonymizeIp", true) |
| 69 | + ga("send", "pageview") |
| 70 | + |
| 71 | + /* Register virtual event handlers */ |
| 72 | + document.addEventListener("DOMContentLoaded", function() { |
| 73 | + if (document.forms.search) { |
| 74 | + var query = document.forms.search.query |
| 75 | + query.addEventListener("blur", function() { |
| 76 | + if (this.value) { |
| 77 | + var path = document.location.pathname; |
| 78 | + ga("send", "pageview", path + "?q=" + this.value) |
| 79 | + } |
| 80 | + }) |
| 81 | + } |
| 82 | + |
| 83 | + /* Send page view on location change */ |
| 84 | + if (typeof location$ !== "undefined") |
| 85 | + location$.subscribe(function(url) { |
| 86 | + ga("send", "pageview", url.pathname) |
| 87 | + }) |
| 88 | + }) |
| 89 | + </script> |
| 90 | + <script async src="https://www.google-analytics.com/analytics.js"></script> |
| 91 | +{% endif %} |
| 92 | + |
| 93 | + |
0 commit comments