> For the complete documentation index, see [llms.txt](https://help.wotnot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.wotnot.io/build/integrations/native/google-analytics/using-javascript.md).

# Using Javascript

## Step 1: Make sure that the Google Analytics 4 code snippet is present

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.&#x20;

## Step 2: Add the Javascript block on the chatbot flow

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

```
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.&#x20;

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

<figure><img src="/files/P4u74eSVPqXoRW4WAelW" 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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.wotnot.io/build/integrations/native/google-analytics/using-javascript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
