Question: Does the HS tracking code script (<script type=“text/javascript” id=“hs-script-loader” async defer src="js.hs-scripts.com/XXXXXXX.js "></script>) provides the same functions as the HS Conversation API scripts seend below:
<script type="text/javascript">
function onConversationsAPIReady() {
//console.log(`HubSpot Conversations API: ${window.HubSpotConversations}`);
window.HubSpotConversations.on( 'conversationStarted', function(payload) {
//console.log("HubSpot Conversation Started");
window.dataLayer.push({
'event': 'HubSpot',
'hs-action': 'conversation-started',
'hs-conversation-id': payload.conversation.conversationId
})
});
//Listens for the conversation window to be closed
window.HubSpotConversations.on( 'conversationClosed', function(payload) {
//console.log("HubSpot Conversation Closed");
//This means the conversation is fully closed. Minimizing doesn't count.
window.dataLayer.push({
'event': 'HubSpot',
'hs-action': 'conversation-closed',
'hs-conversation-id': payload.conversation.conversationId
})
});
//Listens for a change in the number of unread messages
window.HubSpotConversations.on( 'unreadConversationCountChanged', function(payload) {
//console.log("HubSpot Unread Messages Count Change");
window.dataLayer.push({
'event': 'HubSpot',
'hs-action': 'unread-message-count-change',
'hs-conversation-id': payload.unreadCount
})
});
}
/*
If external API methods are already available, use them.
*/
if (window.HubSpotConversations) {
//console.log('The api is ready already');
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];
}
</script>