<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: hubspot cookie callback in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/438326#M23140</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;It can be considered a workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you do not have the cookie (page was loaded for the first time) ... run this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;		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);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you have the cookie, verified by the getCookieGeneric function (which I posted up there) take the value and call our widget.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is not ideal, more is something, if anyone has any better ideas please post here below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 May 2021 18:08:46 GMT</pubDate>
    <dc:creator>FViana</dc:creator>
    <dc:date>2021-05-17T18:08:46Z</dc:date>
    <item>
      <title>hubspot cookie callback</title>
      <link>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/435978#M22999</link>
      <description>&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;Hey!&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;I need help, we have a website with the integration of the hubspot in the contact forms and in the widget of our bot.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;However, our widget is loaded before the hubspot by the wordpress footer script.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;Is there any way to place a callback on the main hubspot script?&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;so that our widget is loaded with the value of the hubspotutk variable?&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;We are currently trying to get the cookie like this, but our script must 'wait' for the hubspot,&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;as the value does not exist, the variable is empty.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;
function getCookieGeneric(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for (var i = 0; i &amp;lt; ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

var prechat_inputs = {};
prechat_inputs["hubspotutk"] = getCookieGeneric('hubspotutk');

var chatbotKey = 'someKEYHere';

(function(d, r, o, z, a, k, t) {
        a = d.getElementsByTagName('head')[0];
        k = d.createElement('script');
        k.async = 1;
        t = (Math.floor(Math.random() * 1000000) + 1);
        k.src=r + '/' + o + '/droz.js?i=' + z + '&amp;amp;u=' + r + '&amp;amp;v=' + t;
        a.appendChild(k);
    })(document, 'https://chat-app.meudroz.com', 'v1', chatbotKey);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 18:23:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/435978#M22999</guid>
      <dc:creator>FViana</dc:creator>
      <dc:date>2021-05-10T18:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: hubspot cookie callback</title>
      <link>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/436302#M23017</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/103660"&gt;@piersg&lt;/a&gt; , &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/73772"&gt;@Kevin-C&lt;/a&gt;&amp;nbsp; how would you handle this?&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 13:56:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/436302#M23017</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-05-11T13:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: hubspot cookie callback</title>
      <link>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/438259#M23137</link>
      <description>&lt;P&gt;Anyone can help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 15:51:33 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/438259#M23137</guid>
      <dc:creator>FViana</dc:creator>
      <dc:date>2021-05-17T15:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: hubspot cookie callback</title>
      <link>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/438326#M23140</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;It can be considered a workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you do not have the cookie (page was loaded for the first time) ... run this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;		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);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you have the cookie, verified by the getCookieGeneric function (which I posted up there) take the value and call our widget.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is not ideal, more is something, if anyone has any better ideas please post here below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 18:08:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/438326#M23140</guid>
      <dc:creator>FViana</dc:creator>
      <dc:date>2021-05-17T18:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: hubspot cookie callback</title>
      <link>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/439157#M23192</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/13982"&gt;@dennisedson&lt;/a&gt;is this a good solution? &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 18:32:57 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/hubspot-cookie-callback/m-p/439157#M23192</guid>
      <dc:creator>FViana</dc:creator>
      <dc:date>2021-05-19T18:32:57Z</dc:date>
    </item>
  </channel>
</rss>

