# Sample - Collect telemetry measurements using Google Analytics This sample shows how to set up a Web Chat client that will collect telemetry measurements into your own instance of Google Analytics. # Test out the hosted sample - [Try out MockBot](https://microsoft.github.io/BotFramework-WebChat/04.api/l.telemetry-google-analytics) # Things to try out - Open development console in your browser - Type "help" in the send box - In the console log, you will see telemetry measurements sent to Google Analytics # Code > Jump to [completed code](#completed-code) to see the end-result `index.html`. > This sample assumes you have already set up Google Analytics and have the measurement ID ready. This sample is based on the [01.getting-started/a.full-bundle](https://github.com/microsoft/BotFramework-WebChat/tree/main/samples/01.getting-started/a.full-bundle) sample. ## Load Google Analytics SDK (gtag.js) Insert the following snippets to load Google Analytics SDK (gtag.js) on to the page. Replace `GA_MEASUREMENT_ID` with your own measurement ID. ```diff ``` ## Handle `onTelemetry` event Add an event handler to receive telemetry measurements from Web Chat and log them to console. ```diff ``` ## Convert telemetry measurements into Google Analytics measurements Telemetry measurements from Web Chat is slightly different from Google Analytics. Conversion is needed to send measurements to Google Analytics. Events with multiple properties will be expanded into multiple events. ```diff ``` ## Add user ID and version data Record conversation ID, user ID, and Web Chat UI version into the metadata of measurements. ```diff
``` # Further reading [`04.api/k.telemetry-application-insights`](https://github.com/microsoft/BotFramework-WebChat/tree/main/samples/04.api/k.telemetry-application-insights) is a sample that will collect telemetry measurements into your own instance of Azure Application Insights. [Google Analytics gtag.js Documentation](https://developers.google.com/analytics/devguides/collection/gtagjs) ## Full list of Web Chat hosted samples View the list of [available Web Chat samples](https://github.com/microsoft/BotFramework-WebChat/tree/main/samples)