https://www.youtube.com/watch?v=2tiLlyGIhCQ
The following custom script should be added to default LiveChat tracking code:
var response = (function() {
var randNum = Math.floor(Math.random() * (3) +1);
return randNum;
})();
console.log(response)
if (response == 1) { x = 0} else
if (response == 2) { x = 2} else
if (response == 3) { x = 3} else
console.log(x);
window.__lc.group = x;
it should be added below the license number line:
window.__lc.license = 9720060;
here’s a working example that loads one of 3 groups with defined ID’s (0,2,3) randomly on the page:
<script>
window.__lc = window.__lc || {};
window.__lc.license = 9720060;
var response = (function() {
var randNum = Math.floor(Math.random() * (3) +1);
return randNum;
})();
console.log(response)
if (response == 1) { x = 0} else
if (response == 2) { x = 2} else
if (response == 3) { x = 3} else
console.log(x);
window.__lc.group = x;
;(function(n,t,c){function i(n){return e._h?e._h.apply(null,n):e._q.push(n)}var e={_q:[],_h:null,_v:"2.0",on:function(){i(["on",c.call(arguments)])},once:function(){i(["once",c.call(arguments)])},off:function(){i(["off",c.call(arguments)])},get:function(){if(!e._h)throw new Error("[LiveChatWidget] You can't use getters before load.");return i(["get",c.call(arguments)])},call:function(){i(["call",c.call(arguments)])},init:function(){var n=t.createElement("script");n.async=!0,n.type="text/javascript",n.src="<https://cdn.livechatinc.com/tracking.js>",t.head.appendChild(n)}};!n.__lc.asyncInit&&e.init(),n.LiveChatWidget=n.LiveChatWidget||e}(window,document,[].slice))
</script>
<noscript><a href="<https://www.livechatinc.com/chat-with/9720060/>" rel="nofollow">Chat with us</a>, powered by <a href="<https://www.livechatinc.com/?welcome>" rel="noopener nofollow" target="_blank">LiveChat</a></noscript>
the script uses Math.random method to return number between 1 and in this case 3 randomly:
var randNum = Math.floor(Math.random() * (3) +1);
3 can be replaced with any other number - it should be equal to number of groups you want to split the traffic between following:
if (response == 0) { x = 0} else
if (response == 1) { x = 2} else
if (response == 2) { x = 3} else
those 3 lines define that if Math.random method returns:
0, group 0 will load on the page
1, group 2 will load on the page
2, group 3 will load on the page
x = ID of the group that should be loaded
if you have more than 3 groups you’d like to split traffic into - you can of course add more as shown below: