How to track engagement with facebook chat plugin with tag manager?

940 Views Asked by At

I've implemented a custom HTML tag on my website with Google Tag Manager. Right now it sends events to Google Analytics if the dialog is shown. Can I also set up an event that tracks when users actually engage with the plugin, like send a message?

<script>
      window.fbAsyncInit = function() {
        FB.init({
          appId            : '{{Facebook App ID}}',
          autoLogAppEvents : true,
          xfbml            : true,
          version          : 'v3.0'
        });

        FB.Event.subscribe('customerchat.dialogShow', function() {
           dataLayer.push({'event': 'Facebook Customer Chat dialog opened'});
})
      };

      (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "//connect.facebook.net/{{Facebook Locale}}/sdk/xfbml.customerchat.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
    </script>
0

There are 0 best solutions below