Facebook Chat Tracking with Google Tag Manager and Google Analytics

Sometimes, we put Facebook Chat on our website so users can chat with us. If we want to see how users interact with it, we can use Google Analytics. But it’s tricky because Facebook Chat comes in an iframe, which makes it hard to track with Google Tag Manager and Google Analytics.

To solve this problem, I’ve created a tool that can track Facebook Chat using GTM and GA4.

Facebook Chat GTM DataLayer

<script>
/**
* Author: Md Hasanuzzamna
* Linkedin: https://linkedin.com/in/md-h
* Youtube: https://youtube.com/@leomeasure
* Email: info@leomeasure.com
*/
    window.addEventListener('message', function (event) {
        if(event.origin.includes('facebook.com') && event.data.includes('%22euit%22%')) {
            window.dataLayer = window.dataLayer || [];
            dataLayer.push({event: 'fb_chat_click'});
        }
    });
</script>

Leave a Comment

Your email address will not be published. Required fields are marked *

Get A Quote

Please contact us for expert guidance & personalized solutions to maximizing the potential of Google Analytics for your business.

Send Us A Message

    Contact Us

    Please contact us for expert guidance & personalized solutions to maximizing the potential of Google Analytics for your business.

    Send Us A Message