# Manual Tracking

When tracking Search, Add To Cart, and Purchases via Server Events is not enough, Events can be sent via a Twig function in your templates.

# Twig Function

Server Events can manually be sent by the fbEvent Twig function.

For example:

{{ fbEvent('Purchase', {
    'email': '[email protected]',
    'first_name': 'Jack',
    'last_name': 'Timberlake'
}, {
    'currency': 'EUR',
    'value': 20,
}) }}
  • The first parameter is the Event Name. Both Custom Events (opens new window) as Standard Events (opens new window) are supported. (Required)
  • The second parameter is Customer Information. By default, the already known User data (of an earlier purchase or fbclid) will be used. Only add the information when you're certain it contains the latest data. (Optional)
  • The third parameter is the Custom Data. (Optional)

All Customer Information and Custom Data parameters are supported, for a full list see the Facebook Documentation (opens new window). The Main Body and Server Event parameters are handled by the Plugin. Hashing is also handled by the Plugin and should not be done in the Twig function.

# Pageview example

When you would like to send the Pageview events by the Server, and not by the Client, use the simplest Twig function:

{{ fbEvent('Pageview') }}

The known User information will automatically be added and no custom data is needed for the Pageview Event.


When tracking the Pageview Event via a Server event, make sure it is not sent via the client. Remove the Facebook Pixel (or Template Hook) from your template.

# Cached pages

When the page is cached by Blitz, Nginx, Varnish, or a CDN, the Twig function would not be triggered. In this case, you would need to do a javascript request to a dynamic part of your website. One simple way to do so is by creating a dynamic folder in your templates and excluding it from your cache.

Create a file (e.g. viewevent.twig) in the excluded folder and paste the twig function that you would use into it:

{{ fbEvent('Pageview') }}

Now on every page the event should be triggered, request the not cached snippet. For example:

<script type="text/javascript">

Note that in this example the javascript fetch is used, which is not supported by Internet Explorer, see the MDN documentation (opens new window). The same can also be accomplished by Jquery's Ajax function or other methods.