Last active
April 4, 2023 18:08
-
-
Save sukhikh18/3969c7928aa9271063ebc6b48dd8b9c4 to your computer and use it in GitHub Desktop.
Load jivosite after custom event (for google pagespeed insights for ex.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- BEGIN JIVOSITE CODE {literal} --> | |
<script type='text/javascript'> | |
(function(){ | |
var widget_id = '#YOUR_API_KEY#'; | |
document.jivositeloaded = 0; | |
var d = document; | |
var w = window; | |
function load() { | |
// Insert script tag before another first script | |
var s = d.createElement('script'); | |
s.type = 'text/javascript'; | |
s.async = true; s.src = '//code.jivosite.com/script/widget/'+widget_id; | |
var ss = document.getElementsByTagName('script')[0]; | |
ss.parentNode.insertBefore(s, ss); | |
} | |
function zy() { | |
// delete event listeners | |
if(w.detachEvent){ // IE8 | |
w.detachEvent('onscroll', zy); | |
w.detachEvent('onmousemove', zy); | |
w.detachEvent('ontouchmove', zy); | |
w.detachEvent('onresize', zy); | |
} | |
else { | |
w.removeEventListener("scroll", zy, false); | |
w.removeEventListener("mousemove", zy, false); | |
w.removeEventListener("touchmove", zy, false); | |
w.removeEventListener("resize", zy, false); | |
} | |
// Load or set load event | |
if(d.readyState=='complete') { | |
load(); | |
} | |
else { | |
if(w.attachEvent) { | |
w.attachEvent('onload', load); | |
} | |
else { | |
w.addEventListener('load', load, false); | |
} | |
} | |
// Set cookie | |
var CookieliveDate = new Date(); | |
CookieliveDate.setTime(CookieliveDate.getTime() + 60*60*24*1000); // +24 hours | |
d.cookie = "JivoSiteLoaded=1;path=/;expires=" + CookieliveDate.toString(); | |
} | |
if (d.cookie.search ( 'JivoSiteLoaded' ) < 0) { | |
if(w.attachEvent) { // IE8 | |
w.attachEvent('onscroll', zy); | |
w.attachEvent('onmousemove', zy); | |
w.attachEvent('ontouchmove', zy); | |
w.attachEvent('onresize', zy); | |
}else { | |
w.addEventListener("scroll", zy, {capture: false, passive: true}); | |
w.addEventListener("mousemove", zy, {capture: false, passive: true}); | |
w.addEventListener("touchmove", zy, {capture: false, passive: true}); | |
w.addEventListener("resize", zy, {capture: false, passive: true}); | |
} | |
} | |
// has cookie (try load) | |
else { | |
zy(); | |
} | |
})();</script> | |
<!-- {/literal} END JIVOSITE CODE --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment