<?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: Wordpress &amp;amp; HubSpot Visitor Identification API in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/605555#M52082</link>
    <description>&lt;P&gt;Thank you so much for posting this!&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2022 20:33:11 GMT</pubDate>
    <dc:creator>dennisedson</dc:creator>
    <dc:date>2022-03-31T20:33:11Z</dc:date>
    <item>
      <title>Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/400520#M39594</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to add the Vistior Identification API to my wordpress site that uses the Hubspot Wordpress Plugin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was adding a custom WP Plugin to handle this small addon. I think I am close to getting it working as I am able to retrive the token on the server and pass it to the client in JS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where I seem to be getting stuck on is getting the Chat to accept the loadImmediately False to delay the loading of the chat until I receive the token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think my issue is a timing issue when Wordpress loads the scripts but maybe I am wrong. Here is the JS that should be loading initially to stop the chat from loading. I have tried loading this from through WP Actions on init, wp_enqueue_scripts,wp_head, and wp_footer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea what I am missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onConversationsAPIReady() {
    console.log(`HubSpot Conversations API: ${window.HubSpotConversations}`);
	window.hsConversationsSettings = {
                loadImmediately: false,
            };
	console.log(window.hsConversationsSettings.loadImmediately);
  }
  
   /*
   If external API methods are already available, use them.
  */
  if (window.HubSpotConversations) {
    onConversationsAPIReady();
  } else {
    /*
      Otherwise, callbacks can be added to the hsConversationsOnReady on the window object.
      These callbacks will be called once the external API has been initialized.
    */
    window.hsConversationsOnReady = [onConversationsAPIReady];
  }
  
	console.log("Include Stop Load");&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;	console.log('&amp;lt;?php echo $response ?&amp;gt;');
	console.log('&amp;lt;?php echo $current_user-&amp;gt;user_email?&amp;gt;');
	window.hsConversationsSettings = {
		identificationEmail: '&amp;lt;?php echo $current_user-&amp;gt;user_email?&amp;gt;',
		identificationToken: '&amp;lt;?php echo $response ?&amp;gt;'
	};
	window.hsConversationsOnReady = [
                () =&amp;gt; {
                    console.log('OnReady');
					window.HubSpotConversations.widget.load();
                },
            ];
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;add_action( 'wp_head', 'Hubspot_Chat_Stop_Load');
add_action( 'wp_footer', 'Hubspot_Chat_User_Verify');


function Hubspot_Chat_User_Verify () { 

$current_user = wp_get_current_user(); 
if ( $current_user-&amp;gt;user_email != "" ) {
	$apiKey = "&amp;lt;&amp;lt;API KEY&amp;gt;&amp;gt;"; //API Key from Hubspot
	
	$email = $current_user-&amp;gt;user_email;
	$fn = $current_user-&amp;gt;user_firstname;
	$ln = $current_user-&amp;gt;user_lastname;

	/* https://packagist.org/packages/hubspot/api-client */
	$curl = curl_init();
	
	curl_setopt_array($curl, array(
		CURLOPT_URL =&amp;gt; "https://api.hubapi.com/conversations/v3/visitor-identification/tokens/create?hapikey=".$apiKey,
		CURLOPT_RETURNTRANSFER =&amp;gt; true,
		CURLOPT_ENCODING =&amp;gt; "",
		CURLOPT_MAXREDIRS =&amp;gt; 10,
		CURLOPT_TIMEOUT =&amp;gt; 30,
		CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST =&amp;gt; "POST",
		CURLOPT_POSTFIELDS =&amp;gt; "{\"email\":\"".$email."\",\"firstName\":\"".$fn."\",\"lastName\":\"".$ln."\"}",
		CURLOPT_HTTPHEADER =&amp;gt; array(
			"accept: application/json",
			"content-type: application/json"
		),
	));

	$response = curl_exec($curl);
	$err = curl_error($curl);

	curl_close($curl);

	include(plugin_dir_path( __DIR__ ) . "hubspot-chat-user-verify/include.php");

}
}

function Hubspot_Chat_Stop_Load () {
	include(plugin_dir_path( __DIR__ ) . "hubspot-chat-user-verify/stopLoad.php");
	
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 19:36:29 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/400520#M39594</guid>
      <dc:creator>jorge-gbs</dc:creator>
      <dc:date>2021-01-18T19:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/401094#M39661</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/149190"&gt;@jorge-gbs&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you still working through this?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/67091"&gt;@prosa&lt;/a&gt;&amp;nbsp; do you have any thoughts on this?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 17:11:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/401094#M39661</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-01-19T17:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/401136#M39679</link>
      <description>&lt;P&gt;Hello, Yes I still am trying to figure it out.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 19:23:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/401136#M39679</guid>
      <dc:creator>jorge-gbs</dc:creator>
      <dc:date>2021-01-19T19:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/403484#M39953</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/13982"&gt;@dennisedson&lt;/a&gt;&amp;nbsp;Any help on this would be greatly appriciated. I wouldn't mind publishing this on Github for public use as it seems like a useful piece of code for anyone running wordpress and Hubspot. Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 02:15:56 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/403484#M39953</guid>
      <dc:creator>jorge-gbs</dc:creator>
      <dc:date>2021-01-27T02:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/403487#M39954</link>
      <description>Ah &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/48881"&gt;@Jorge&lt;/a&gt;-gb &lt;BR /&gt;Sorry I didn't see this still out there.  I will look more closely tomorrow.&lt;BR /&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259"&gt;@Mike_Eastwood&lt;/a&gt; is a real pro an might have an idea as well, though!</description>
      <pubDate>Wed, 27 Jan 2021 02:24:56 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/403487#M39954</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-01-27T02:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/409183#M40526</link>
      <description>&lt;P&gt;It's dissapointing that support of this API is not even planned for implementation in HubSpot WP plugin (we enquired).&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/13982"&gt;@dennisedson&lt;/a&gt;&amp;nbsp; can you please get HubSpot devs to provide working snippets and how-to for implementing this API in the presence of HubSpot WP plugin?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 05:13:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/409183#M40526</guid>
      <dc:creator>Den</dc:creator>
      <dc:date>2021-02-15T05:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/605524#M52080</link>
      <description>&lt;P&gt;In case this helps anyone. I figured it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code was correct. Just missing in the JS the Token I was passing the entire array including Keys instead of just the token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The line read:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	console.log('&amp;lt;?php echo $response ?&amp;gt;');
	console.log('&amp;lt;?php echo $current_user-&amp;gt;user_email?&amp;gt;');
	window.hsConversationsSettings = {
		identificationEmail: '&amp;lt;?php echo $current_user-&amp;gt;user_email?&amp;gt;',
		identificationToken: '&amp;lt;?php echo $response ?&amp;gt;'
	};
	window.hsConversationsOnReady = [
                () =&amp;gt; {
                    console.log('OnReady');
					window.HubSpotConversations.widget.load();
                },
            ];
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should read:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;script type="text/javascript" id="passUserID"&amp;gt;
	window.hsConversationsSettings = {
		loadImmediately: false,
		identificationEmail: '&amp;lt;?php echo $current_user-&amp;gt;user_email?&amp;gt;',
		identificationToken: '&amp;lt;?php echo $response['token'] ?&amp;gt;'
	};
	window.hsConversationsOnReady = [
                () =&amp;gt; {
                    console.log('OnReady');
					window.HubSpotConversations.widget.load();
                },
            ];
    
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 16:00:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/605524#M52080</guid>
      <dc:creator>jorge-gbs</dc:creator>
      <dc:date>2022-04-01T16:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Wordpress &amp; HubSpot Visitor Identification API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/605555#M52082</link>
      <description>&lt;P&gt;Thank you so much for posting this!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 20:33:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Wordpress-amp-HubSpot-Visitor-Identification-API/m-p/605555#M52082</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2022-03-31T20:33:11Z</dc:date>
    </item>
  </channel>
</rss>

