analytics_opt_out.html
34 lignes · 1688 octets
{# Visitor opt-out for audience measurement. Generalisation of the vendor-specific snippet: the localStorage key comes from `AnalyticsConfig::opt_out_storage_key` instead of being hardcoded, and the labels come from the framework's i18n rather than an inline cascade of locale tests. Most vendors no-op entirely when their `disable-<namespace>` key exists. The flag is read at script initialisation only, so a change takes effect on the next page load — hence the wording of the hint. The two labels are rendered as separate `x-show` spans rather than through `x-text`, because a translation containing an apostrophe ("M'opposer") would otherwise terminate the JavaScript string literal: Askama escapes it to `'`, which the browser decodes back to `'` before Alpine evaluates the expression. Requires the parent template to carry an `analytics_opt_out` field (`AnalyticsOptOutContext`). Renders nothing when no key is configured. #} {% if analytics_opt_out.has_key() %} <div class="mt-4 pt-4 border-t border-base-300" x-data="analyticsOptOut" data-storage-key="{{ analytics_opt_out.storage_key }}"> <p class="text-sm text-base-content/70 mb-2">{{ analytics_opt_out.hint }}</p> <div class="flex items-center gap-3 flex-wrap"> <button type="button" class="btn btn-sm btn-outline" @click="toggle()"> <span x-show="!optedOut">{{ analytics_opt_out.opt_out_label }}</span> <span x-show="optedOut" x-cloak>{{ analytics_opt_out.opt_in_label }}</span> </button> <span class="badge badge-success badge-sm" x-show="optedOut" x-cloak>{{ analytics_opt_out.opted_out_badge }}</span> </div> </div> {% endif %}
GitRust