I found a solution, but I haven’t tested it yet, I believe there is an easier way but I haven’t found it anywhere.
It can be considered a workaround.
If you do not have the cookie (page was loaded for the first time) … run this:
var checkCookie = function() {
var lastCookies = document.cookie.split( ';' ).map( function( x ) { return x.trim().split( /(=)/ ); } ).reduce( function( a, b ) {
a[ b[ 0 ] ] = a[ b[ 0 ] ] ? a[ b[ 0 ] ] + ', ' + b.slice( 2 ).join( '' ) :
b.slice( 2 ).join( '' ); return a; }, {} );
return function() {
var currentCookies = document.cookie.split( ';' ).map( function( x ) { return x.trim().split( /(=)/ ); } ).reduce( function( a, b ) {
a[ b[ 0 ] ] = a[ b[ 0 ] ] ? a[ b[ 0 ] ] + ', ' + b.slice( 2 ).join( '' ) :
b.slice( 2 ).join( '' ); return a; }, {} );
for(cookie in currentCookies) {
if ( currentCookies[cookie] != lastCookies[cookie] ) {
console.log("--------")
console.log(cookie+"="+lastCookies[cookie])
console.log(cookie+"="+currentCookies[cookie])
// get value from hubspotutk !!
// call my widget
}
}
lastCookies = currentCookies;
};
}();
window.setInterval(checkCookie, 100);
if you have the cookie, verified by the getCookieGeneric function (which I posted up there) take the value and call our widget.
This is not ideal, more is something, if anyone has any better ideas please post here below