I am trying to prevent my chatbot from loading immediately on my page using the above code, but for some reason the code doesn't work, the bot is loading on the page.
On my end, I have clone out the page and name it as hstest that is using a clone template and a clone javascript file. I made two changes here:
#1 When looking at the placement of your javascript file, I noticed you added both the tracking code and chatbot-script javascript in the 'Additional markup before </body>'. I shifted it to the 'Additional <head> markup' so that the script is loaded before anything else.
#2 In the javascript file, I removed $(document).ready(function() {
"The API is housed in the window.HubSpotConversations object. All available methods can be accessed via this object. The HubSpot script loader on your page will create this object for you, but it may not be available immediately. To defer accessing the API until it has been initialized, you may use the window.hsConversationsOnReady helper. "
And so, can you try the following code and see if this works for you:
1. The code to prevent the bot from loading inside the "if (window.HubSpotConversations) {" statement, does not work. The bot still shows when we go into that IF statement.
2. The "window.hsConversationsOnReady" deferrer is not always called. (try refreshing a few times and you'll see that the message I am logging does not always come through)
On my end, I have clone out the page and name it as hstest that is using a clone template and a clone javascript file. I made two changes here:
#1 When looking at the placement of your javascript file, I noticed you added both the tracking code and chatbot-script javascript in the 'Additional markup before </body>'. I shifted it to the 'Additional <head> markup' so that the script is loaded before anything else.
#2 In the javascript file, I removed $(document).ready(function() {
The code works well for me, however I am still having a problem with my first point .
1. The code to prevent the bot from loading inside the "if (window.HubSpotConversations) {" statement, does not work. The bot still shows when we go into that IF statement.
That's because the HubSpot script loader on your page will create the window.HubSpotConversations for you, but it may not be available immediately and hence we need another else statement to defer accessing the API until it has been initialized by using window.hsConversationsOnReady.