# Using Javascript

## Step 1: Make sure that the Google Analytics 4 code snippet is present <a href="#step-1-make-sure-that-the-google-analytics-4-code-snippet-is-present" id="step-1-make-sure-that-the-google-analytics-4-code-snippet-is-present"></a>

In order to fire events to your measurement ID, you need to first make sure that the Google Analytics code snippet is already added to your website. Usually, website either add it manually on the code or using Google Tag Manager.

## Step 2: Add the Javascript block on the chatbot flow <a href="#step-2-add-the-javascript-block-on-the-chatbot-flow" id="step-2-add-the-javascript-block-on-the-chatbot-flow"></a>

At the point in the chatbot flow when you want to fire an event, add the Javascript action block and input this code.

```
window.dataLayer = window.dataLayer || [];
function gtag() {
  window.dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "YOUR-MEASUREMENT-ID");
gtag("event", "YOUR-EVENT-NAME", {
  "send_to": "YOUR-MEASUREMENT-ID"
  // ADDITIONAL PARAMETERS THAT YOU MAY WANT TO PASS
});
```

Make sure you add the MEASUREMENT ID of your GA4 property in the mentioned places. And also, use the event name as per your requirement.

You can find your MEASUREMENT ID by navigating to the Settings -> Data collection -> Data streams

<figure><img src="https://3672643579-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1seyhUNyGxp6NBkWb6e3%2Fuploads%2FFNtKHFBzOprmWMtO8uHq%2FScreenshot%202025-05-08%20154043.png?alt=media&#x26;token=cb142ea9-8062-4cdd-8987-0b8e7d85e957" alt=""><figcaption><p>Measurement ID of a GA4 property</p></figcaption></figure>

Refer to this page for default GA events -- <https://developers.google.com/analytics/devguides/collection/gtagjs/events>

{% hint style="warning" %}
Note that it takes about 20-30 seconds for events to reflect in Google Analytics
{% endhint %}
