Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback form POC #2335

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,27 @@ extra:
url: '/projects/userguide'
- title: 'Connect Documentation'
url: '/projects/connect'
analytics:
provider: google
property: GTM-KKQR5LG
feedback:
title: Was this page helpful?
ratings:
- icon: material/emoticon-happy-outline
name: This page was helpful
data: 1
note: >-
Thanks for your feedback!
- icon: material/emoticon-sad-outline
name: This page could be improved
data: 0
note: >-
Thanks for your feedback! Help us improve this page by
using our <a href="url" target="_blank" rel="noopener">feedback form</a><br/>

Create an issue on JIRA<br/>
<a href="{edit_url}" class="source-github">Suggest an improvement on GitHub</a><br/>
<a href="https://github.com/ibexa/docker/issues/new?title=[Feedback]+{title}+-+{url}" class="source-github">Create an issue on GitHub</a>

# Global variables
site_display_name: 'Ibexa Documentation'
Expand Down
8 changes: 8 additions & 0 deletions theme/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
{%- endif -%}
{% endblock %}


<!-- Analytics -->
{% block analytics %}
{% include "partials/integrations/analytics.html" %}
{% endblock %}

{% block extrahead %}
<meta name="google-site-verification" content="zttxcBm_blrd3kCAsNlGZqvzga_-8ovH4IxSHw2l5OQ" />
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-KKQR5LG');</script> <!-- End Google Tag Manager -->
Expand Down Expand Up @@ -68,6 +74,8 @@
</div>
{% endif %}
{{ page.content }}
<!-- Was this page helpful? -->
{% include "partials/feedback.html" %}
{% include "partials/tags.html" %}
</div>
{% endblock %}
79 changes: 79 additions & 0 deletions theme/partials/feedback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!--
Copyright (c) 2016-2024 Martin Donath <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->

<!-- Determine feedback configuration -->
{% if config.extra.analytics %}
{% set feedback = config.extra.analytics.feedback %}
{% endif %}

<!-- Determine whether to show feedback -->
{% if page.meta and page.meta.hide %}
{% if "feedback" in page.meta.hide %}
{% set feedback = None %}
{% endif %}
{% endif %}

<!-- Was this page helpful? -->
{% if feedback %}
<form class="md-feedback" name="feedback" hidden>
<fieldset>
<legend class="md-feedback__title">
{{ feedback.title }}
</legend>
<div class="md-feedback__inner">

<!-- Feedback ratings -->
<div class="md-feedback__list">
{% for rating in feedback.ratings %}
<button
class="md-feedback__icon md-icon"
type="submit"
title="{{ rating.name }}"
data-md-value="{{ rating.data }}"
>
{% include ".icons/" ~ rating.icon ~ ".svg" %}
</button>
{% endfor %}
</div>

<!-- Feedback rating notes (shown after submission) -->
<div class="md-feedback__note">
{% for rating in feedback.ratings %}
<div data-md-value="{{ rating.data }}" hidden>
{% set url = "/" ~ page.url %}

<!-- Determine title -->
{% if page.meta and page.meta.title %}
{% set title = page.meta.title | urlencode %}
{% else %}
{% set title = page.title | urlencode %}
{% endif %}

<!-- Replace {url} and {title} placeholders in note -->
{{ rating.note.format(url = url, title = title, edit_url = page.edit_url|replace('/edit/', '/blob/')) }}
</div>
{% endfor %}
</div>
</div>
</fieldset>
</form>
{% endif %}
50 changes: 49 additions & 1 deletion theme/partials/integrations/analytics.html
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
<script>!function(e,a,t,n,o,c,i){e.GoogleAnalyticsObject=o,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,c=a.createElement(t),i=a.getElementsByTagName(t)[0],c.async=1,c.src="https://www.google-analytics.com/analytics.js",i.parentNode.insertBefore(c,i)}(window,document,"script",0,"ga"),ga("create","{{ config.google_analytics[0] }}","{{ config.google_analytics[1] }}"),ga("set","anonymizeIp",!0),ga("send","pageview");var links=document.getElementsByTagName("a");if(Array.prototype.map.call(links,function(e){e.host!=document.location.host&&e.addEventListener("click",function(){var a=e.getAttribute("data-md-action")||"follow";ga("send","event","outbound",a,e.href)})}),document.forms.search){var query=document.forms.search.query;query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})}</script>
<!--
Copyright (c) 2016-2024 Martin Donath <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->

<!-- Determine analytics provider -->
{% if config.extra.analytics %}
{% set provider = config.extra.analytics.provider %}
{% endif %}

<!-- Set up analytics provider -->
{% if provider %}
{% include "partials/integrations/analytics/" ~ provider ~ ".html" %}

<!-- Consent necessary -->
{% if config.extra.consent %}
<script>
if (typeof __md_analytics !== "undefined") {
var consent = __md_get("__consent")
if (consent && consent.analytics)
__md_analytics()
}
</script>

<!-- Consent unnecessary -->
{% else %}
<script>
if (typeof __md_analytics !== "undefined")
__md_analytics()
</script>
{% endif %}
{% endif %}
97 changes: 97 additions & 0 deletions theme/partials/integrations/analytics/google.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!--
Copyright (c) 2016-2024 Martin Donath <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->

<!-- Determine analytics property -->
{% if config.extra.analytics %}
{% set property = config.extra.analytics.property | d("", true) %}
{% endif %}

<!-- Integrate with Google Analytics 4 -->
<script id="__analytics">
function __md_analytics() {
window.dataLayer = window.dataLayer || []
function gtag() { dataLayer.push(arguments) }

/* Set up integration and send page view */
gtag("js", new Date())
gtag("config", "{{ property }}")

/* Register event handlers after documented loaded */
document.addEventListener("DOMContentLoaded", function() {

/* Set up search tracking */
if (document.forms.search) {
var query = document.forms.search.query
query.addEventListener("blur", function() {
if (this.value)
gtag("event", "search", { search_term: this.value })
})
}

/* Set up feedback, i.e. "Was this page helpful?" */
document$.subscribe(function() {
var feedback = document.forms.feedback
if (typeof feedback === "undefined")
return

/* Send feedback to Google Analytics */
for (var button of feedback.querySelectorAll("[type=submit]")) {
button.addEventListener("click", function(ev) {
ev.preventDefault()

/* Retrieve and send data */
var page = document.location.pathname
var data = this.getAttribute("data-md-value")
gtag("event", "feedback", { page, data })

/* Disable form and show note, if given */
feedback.firstElementChild.disabled = true
var note = feedback.querySelector(
".md-feedback__note [data-md-value='" + data + "']"
)
if (note)
note.hidden = false
})

/* Show feedback */
feedback.hidden = false
}
})

/* Send page view on location change */
location$.subscribe(function(url) {
gtag("config", "{{ property }}", {
page_path: url.pathname
})
})
})

/* Create script tag */
var script = document.createElement("script")
script.async = true
script.src = "https://www.googletagmanager.com/gtag/js?id={{ property }}"

/* Inject script tag */
var container = document.getElementById("__analytics")
container.insertAdjacentElement("afterEnd", script)
}
</script>
Loading