Mark Fulton Mark Fulton - 3 months ago 18
Javascript Question

Tracking a chat window event, how do I get these two scripts to work together?

I am trying to track an event using the following code, but to me it seems like they are not immediately compatible as what I wanted to do was not validating.

Tawk_API = Tawk_API || {};
Tawk_API.onChatStarted = function(){
//place your code here
};


How would I add this event tracking code to the above?

<script type="text/javascript">
//<![CDATA[
wc_event_ypbib
(
"User", //Category - Required
"Chat", //Action - Required
"New Chat", //Label - Optional
);
//]]>
</script>


Thank you for any help you can provide.

Answer

Basically, just place your code where it says "place your code here." Like so:

Tawk_API = Tawk_API || {};
Tawk_API.onChatStarted = function(){
  //place your code here
  wc_event_ypbib
  (
    "User", //Category - Required
    "Chat", //Action - Required
    "New Chat" //Label - Optional
  );
};