# Google Firebase Analytics

{% hint style="info" %}

<pre data-overflow="wrap"><code>You'll need to import the javascript file in your website before starting from this <a data-footnote-ref href="#user-content-fn-1">link</a>.
</code></pre>

{% endhint %}

1\) To enable/disable Analytics data collection

{% tabs %}
{% tab title="Plain JS" %}

```markup
const { Analytics: FirebaseAnalytics } = window.WTN.Firebase

FirebaseAnalytics.setCollection({
    enabled: true/false
})

```

{% endtab %}

{% tab title="ES 6+" %}

```
import { setCollection } from "webtonative/Firebase/Analytics"

setCollection({
    enabled: true/false
})

```

{% endtab %}
{% endtabs %}

2\) To identify user

{% tabs %}
{% tab title="Plain JS" %}

```markup
const { Analytics: FirebaseAnalytics } = window.WTN.Firebase

FirebaseAnalytics.setUserId({
    userId: "customuserId"
})

```

{% endtab %}

{% tab title="ES 6+" %}

```
import { setUserId } from "webtonative/Firebase/Analytics"

setUserId({
    userId: "customuserId"
})

```

{% endtab %}
{% endtabs %}

3\) To set user properties like name, gender etc

{% tabs %}
{% tab title="Plain JS" %}

```markup
const { Analytics: FirebaseAnalytics } = window.WTN.Firebase

FirebaseAnalytics.setUserProperty({
    key: 'name',
    value:'Webtonative'
})

```

{% endtab %}

{% tab title="ES 6+" %}

```
import { setUserProperty } from "webtonative/Firebase/Analytics"

setUserProperty({
    key: 'name',
    value:'Webtonative'
})

```

{% endtab %}
{% endtabs %}

4\) To set default parameter which will be passed along with all future events

{% tabs %}
{% tab title="Plain JS" %}

```markup
const { Analytics: FirebaseAnalytics } = window.WTN.Firebase

FirebaseAnalytics.setDefaultEventParameters({
    parameters: {
        "level_name": "Caverns01",
        "level_difficulty": 4
    }
})

```

{% endtab %}

{% tab title="ES 6+" %}

```
import { setDefaultEventParameters } from "webtonative/Firebase/Analytics"

setDefaultEventParameters({
    parameters: {
        "level_name": "Caverns01",
        "level_difficulty": 4
    }
})

```

{% endtab %}
{% endtabs %}

5\) To Log events

{% tabs %}
{% tab title="Plain JS" %}

```markup
const { Analytics: FirebaseAnalytics } = window.WTN.Firebase

FirebaseAnalytics.logEvent({
    eventName:'Your event name',
    parameters:{
        "level_name": "Caverns01",
        "level_difficulty": 4
    }
})

```

{% endtab %}

{% tab title="ES 6+" %}

```
import { logEvent } from "webtonative/Firebase/Analytics"

logEvent({
    eventName:'Your event name',
    parameters:{
        "level_name": "Caverns01",
        "level_difficulty": 4
    }
})

```

{% endtab %}
{% endtabs %}

6\) To Track screen view in your website

{% tabs %}
{% tab title="Plain JS" %}

```markup
const { Analytics: FirebaseAnalytics } = window.WTN.Firebase

FirebaseAnalytics.logScreen({
    screenName:"Screen Name",
    screenClass:"Screen Class"
})

```

{% endtab %}

{% tab title="ES 6+" %}

```
import { logScreen } from "webtonative/Firebase/Analytics"

logScreen({
    screenName:"Screen Name",
    screenClass:"Screen Class"
})

```

{% endtab %}
{% endtabs %}

[^1]: <https://docs.webtonative.com/javascript-apis/getting-started>


---

# Agent Instructions: 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:

```
GET https://docs.webtonative.com/javascript-apis/google-firebase-analytics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
