# Facebook App Events

{% 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 %}

## Automatically Logged Events

When using the Facebook SDK, certain events in your app are automatically logged and collected for Facebook Events Manager unless you disable automatic event logging. These events are relevant for all use cases - targeting, measurement and optimisation.\
Learn more about Automatically Logged Events : \
**Android:** <https://developers.facebook.com/docs/app-events/getting-started-app-events-android#auto-events>\
**iOS:** <https://developers.facebook.com/docs/app-events/getting-started-app-events-ios#auto-events>

## Manually Log Events(Custom Events) <a href="#log-manually" id="log-manually"></a>

1\) Regular Events\
To send a custom event to Facebook, create a javascript object with the fields:

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

```markup
const { events: FacebookEvents} = window.WTN.facebook

FacebookEvents.send({
    event: "MY_EVENT", 
    valueToSum: 10, //optional
    parameters: { // optional
        name: "webtonative"
    }
})

```

{% endtab %}

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

```
import { send } from "webtonative/Facebook/events"

send({
    event: "MY_EVENT", 
    valueToSum: 10, //optional
    parameters: { // optional
        name: "webtonative"
    }
})

```

{% endtab %}
{% endtabs %}

2\) Purchase Events\
There is a special case for purchases and Facebook's SDK will send the event more immediately:

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

```markup
const { events: FacebookEvents} = window.WTN.facebook

FacebookEvents.sendPurchase({
    amount: 3.14, 
    currency: "INR",
    parameters: { // optional
        name: "webtonative"
    }
})

```

{% endtab %}

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

```
import { sendPurchase } from "webtonative/Facebook/events"

sendPurchase({
    amount: 3.14, 
    currency: "INR",
    parameters: { // optional
        name: "webtonative"
    }
})

```

{% endtab %}
{% endtabs %}

The list of string constants for event names and parameter keys can be found here:

* **Android**: <https://developers.facebook.com/docs/app-events/reference#standard-events>
* **iOS**: <https://developers.facebook.com/docs/app-events/reference#standard-events-2>

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