HubSpot Chat & Google Analytics Event Tracking

SOLVE
jamesthrasher
Participant

I've used both snippets below to push a GA event whenever a conversation is started, but neither seem to work. Can anyone tell me what I'm doing wrong here?

 

 

//Option A
<script type="text/javascript">
   window.HubSpotConversations.on('conversationStarted', payload => { ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
</script>

//Option B
<script type="text/javascript">
window.HubSpotConversations.on('conversationStarted', function(payload){ ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
</script>

 

 

0 Upvotes
1 Accepted solution

Accepted Solutions
Mike_Eastwood
Solution
Key Advisor | Gold Partner

Looks to me like the HubSpot Javascript is loading after your Javascript fires.

 

So, James added the On Load Event Listener so the Javascript fired after everything loaded.

 

<script type="text/javascript">
window.addEventListener("load", function(){
   window.HubSpotConversations.on('conversationStarted', payload => { ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
});
</script>

Notice the line:

window.addEventListener("load", function(){

and it's closed with

});

 

Have fun

Mike

View solution in original post

4 Replies 4
JessicaH
HubSpot Alumni

Hi @jamesthrasher,

 

Thanks for reaching out.

I want to tag in some subject matter experts to see if they can assist with this.

Hi @derekcavaliero @Mike_Eastwood @MikeCormack, would you be able to share your thoughts with @jamesthrasher?

 

Thanks!

Jess   


Wusstest du, dass es auch eine DACH-Community gibt?
Nimm an regionalen Unterhaltungen teil, in dem du deine Spracheinstellungen änderst !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !


Mike_Eastwood
Key Advisor | Gold Partner

Sorry for the delayed reaction @jamesthrasher 

 

Do you see any errors in your browser's inspector when the page loads?

 

Are you able to share (by direct message) a link to the page you're testing?

 

Or ,did you work it out already?

 

Mike

Mike_Eastwood
Solution
Key Advisor | Gold Partner

Looks to me like the HubSpot Javascript is loading after your Javascript fires.

 

So, James added the On Load Event Listener so the Javascript fired after everything loaded.

 

<script type="text/javascript">
window.addEventListener("load", function(){
   window.HubSpotConversations.on('conversationStarted', payload => { ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
});
</script>

Notice the line:

window.addEventListener("load", function(){

and it's closed with

});

 

Have fun

Mike

View solution in original post

Rortega
Member

Hello!

 

I want to tag the chat with tag manager but when I add your script I get and error: 

---

Hay un error en la línea 3, carácter 58: This language feature is only supported for ECMASCRIPT6 mode or better: arrow function.

---

Do you know how to solve it?

 

Best regards

0 Upvotes