Search code examples
google-analyticsevent-tracking

Not able to track two event on same web page in Google Analytic


Google Analytic not showing tracking for Chat Instantiation, whereas phone click/tap tracking working. Please tell me where I am wrong in the following code. One more thing I am not able to insert code inline, so I used jquery function in header.

<script>
jQuery(function ($) {
    $( document ).ready(function() {
        $(".cont_no").on("click", function(){            
            gtag('event', 'clicks', { event_category: 'Phone Number', event_action: 'Clicked'});
        });

        $(".olark-form-send-button").on("click", function(){            
            gtag('event', 'clicks', { event_category: 'Chat', event_action: 'Chat Initiation'});
        });
    }); 
});
</script>

I want to track both chat and phone click/tap in Google Analytics.


Solution

  • Finally I found solution with the following code:

    <script>
    jQuery(function ($) {
        $( document ).ready(function() {
            $(".cont_no").on("click", function(){            
                gtag('event', 'clicks', { event_category: 'Phone Number', event_action: 'Clicked Website'});
            });
            gtag('event', 'clicks', { event_category: 'Olark_Chat', event_action: 'Visitor_Sent_a_Message', event_lable: 'Visitor_initiated_with_[agent name]'});
        }); 
    });
    </script>