35 lines
1.6 KiB
Plaintext
35 lines
1.6 KiB
Plaintext
{%- comment -%}
|
||
Google Customer Reviews badge (seller rating). Loads on the first user interaction
|
||
so it doesn't affect initial page performance. Configure in Theme settings › Google Customer Reviews.
|
||
{%- endcomment -%}
|
||
{%- if settings.gcr_badge_enabled and settings.gcr_merchant_id != blank -%}
|
||
{%- unless request.design_mode -%}
|
||
<script nolazy>
|
||
(function () {
|
||
var CFG = {
|
||
merchant_id: {{ settings.gcr_merchant_id | strip | plus: 0 }},
|
||
position: {{ settings.gcr_badge_position | default: 'BOTTOM_LEFT' | json }},
|
||
region: {{ settings.gcr_region | default: 'MX' | upcase | json }}
|
||
};
|
||
var EVENTS = ['scroll', 'touchstart', 'pointerdown', 'mousemove', 'keydown', 'wheel'];
|
||
var done = false;
|
||
function inject() {
|
||
var s = document.createElement('script');
|
||
s.id = 'merchantWidgetScript';
|
||
s.src = 'https://www.gstatic.com/shopping/merchant/merchantwidget.js';
|
||
s.defer = true;
|
||
s.setAttribute('nolazy', '');
|
||
s.onload = function () { if (window.merchantwidget) window.merchantwidget.start(CFG); };
|
||
document.body.appendChild(s);
|
||
}
|
||
function go() {
|
||
if (done) return; done = true;
|
||
EVENTS.forEach(function (ev) { window.removeEventListener(ev, go, { passive: true }); });
|
||
if (document.readyState === 'complete') inject(); else window.addEventListener('load', inject, { once: true });
|
||
}
|
||
EVENTS.forEach(function (ev) { window.addEventListener(ev, go, { passive: true }); });
|
||
})();
|
||
</script>
|
||
{%- endunless -%}
|
||
{%- endif -%}
|