Send offline transactions to Facebook

Note: Completing this procedure requires some knowledge on sending API requests using tools such as curl or Postman.

When you save an offline event in Synerise, you can use the Automation module to forward it to Facebook. In this case, use Offline event set to gather such events.

Prerequisites


  • You must have access to a Facebook Ad account
  • You must have permissions that allow you to:
    • Access Data Management, create a schema
    • Access Automation, create an outgoing integration and a workflow
  • Create a customer profile for testing purposes

Process


In order to send offline transactions, follow the steps listed below in the following order:

  1. Authorize in Facebook Ad
  2. Create a schema
  3. Create an Outgoing Integration
  4. Create a workflow

Authorize in Facebook Ad


In this part of the process, in your Facebook Ad account, you will add a System User, grant this user access to your ad account, create a System User Access token, and get Offline Event Set ID.

Tip: This part of the process is performed on your Facebook Ad account. If youโ€™re not familiar with the Facebook Ad user interface, you can read its documentation here.
  1. Go to your account in Facebook Ad > Business Manager > Business Settings.
  2. Select System Users.
  3. Click Add New System User.
    Result: A user is added.
  4. As the role for the new user, select Admin System User.
  5. Grant your new user access to your ad account.
    1. Go to Business Manager > Business Settings.
    2. Select System Users.
    3. Select the new user and click Assign Assets.
    4. Select your ad account.
      Result: The user has access to your ad account.
  6. Go to Business Manager > Business Settings.
  7. Select System Users.
  8. Select the new user and click Generate New Token.
  9. Go to Your app > For scope, select ads_management.
  10. Copy your token, paste it to the notepad for use in the next steps.
    Important: Save the token because it won’t be accessible later. Such token never expires.
  11. Go to Business Manager > Events Manager.
  12. On the list on the left side, you can find the ID.
  13. Copy the ID and paste it to the notepad for use in the next steps.

Create a schema


In this part of the process, you will create a schema needed to the outgoing integration created further in the process. The schema must include three fields that will pass the following information:

  • the ID of the Offline Event Set (a text field)
  • the type of a customer’s identifier (a selector)
  • the customer identifier encoded using SHA-256 (a text field)
Note: You can find more information about Schema Builder here.
  1. Go to Assets > Schema Builder > New schema.

  2. Enter the name of the schema (for example, Facebook Audience).

  3. Drag the Text input component to the schema structure.

  4. Click the text input and then click Pencil icon.

  5. In the Label field, enter Offline Event Set ID.

    The configuration of the Offline Event Set ID field
    The configuration of the Offline Event Set ID field
  6. Confirm by clicking Apply.

  7. Drag the Select component to the schema structure.

  8. Click the select and then click Pencil icon.

  9. In the Label field, enter Type of clients' identifier.

    The configuration of the Type of client's identifier field
    The configuration of the Type of client's identifier field
  10. Go to the Data tab, enter the labels and values for selector options (see screenshot).

    The configuration of the Type of client's identifier field
    The configuration of the Type of client's identifier field
  11. Confirm by clicking Apply.

  12. Drag the Text input component to the schema structure.

  13. Click the select and then click Pencil icon. 8. In the Field Id, enter identifier. 10. In the Label field, enter Client's identifier.

    The configuration of the Client's identifier field
    The configuration of the Client's identifier field
  14. Confirm by clicking Apply.

  15. Save the schema.

    Preview of the schema
    Preview of the schema

Create an outgoing integration


In this part of the process, you prepare an outgoing integration that sends offline events from Synerise to Offline Event Set in Facebook. The integration is built based on the schema you prepared in the earlier part of the process.

The outgoing integration will contain inserts which will refer to the fields in schema and retrieve the values from these fields.

  1. Go to Automation > Outgoing > New integration.

  2. Enter the name of the integration.

  3. Optionally, you can add an icon.

  4. In the Define section:

    1. Select the POST method.
    2. Enter the endpoint (you can find it in the Facebook documentation.
    3. Replace the ID of the Custom Audience with {% context text-input %}.
      For example, in https://graph.facebook.com/v9.0/12345678910111213/users?access_token=, 12345678910111213 must be replaced with {% context text-input %}
    4. Enter the name of the event that will be generated when this integration takes place (for example, send.offline).
    5. Click Apply.
    Settings of Outgoing integration
    Endpoint settings of the Outgoing integration
  5. In the Parameters section, from the dropdown list, select the schema you created in the Create a schema step.

    Settings of Outgoing integration
    Template of the Outgoing integration
  6. In the Webhook payload, paste the following code without modifying anything:

    {   
    "data": [     
          {        
     "match_keys": {            
          "{% context select-field %}": "{% context identifier %}"
             },         
    	"currency": "PLN",         
    	"value": {{ event.params.$totalAmount | float }},         
    	"event_name": "Purchase",         
    	"event_time": {{ ( event.params.time / 1000 ) | int }},         
    	"contents": {% set tab = [] %}{% for p in event.params.products %} {% set obj = {} %}{% set idk = p.sku|string %}{% set quan = p.quantity|int %}{% do obj.update({"id":idk}) %}{% do obj.update({"quantity":quan}) %}{% do tab.append(obj) %}{% endfor %}{{tab|tojson}},         
    	"custom_data": {            
    		"event_source": "in_store"         
    	}      
         }   
    ]
    }
        

    Code explanation:
    - select-field and identifier tags are retrieved from the event (the Outgoing integration) included in the workflow which you will create in the next part of the process.
    - value is the total amount of a transaction
    - event_time is a time stamp of the transaction (a date when transaction was made - it needs to be given in seconds, so the code converts it from milliseconds)
    - contents is an array of objects with SKUs of the products bought in the transaction

    Preview of schema
    Schema preview
  7. Leave the rest of settings at default.

    Payload of the webhook
    Webhook payload
  8. Click Build test.

  9. On the pop-up, fill in the fields. It’s necessary to test if the integration works. If the test is successful, your integration can be used in automations.

    Payload of the webhook
    Building a test based on the test user data
    1. Select a test customer.
    2. Enter the ID of the Offline Event Set.
    3. From the dropdown list, select email.
    4. Enter the email address encoded using SHA-256 algorithm.
      Important: Use any website that hashes an email address using SHA-256 algorithm.
    5. Click Preview.

Create a workflow


Tip: You can prepare a test workflow based on the instructions in this step for a group of test users.

In this part of the process, you will create a workflow that is triggered by a purchase in the point of sales. Through the outgoing integration, the system sends this event to the Offline Event Set in Facebook.

Important: While sending the customers through the outgoing integration, the customer identifiers are encoded using SHA-256.
The final structure of the workflow
The final structure of the workflow

1. Add the Client Event trigger

Configuration of the Client Event trigger
Configuration of the Client Event trigger
  1. In the Synerise app, go to Automation > Workflows > New workflow.
  2. On the dashboard, click the plus button.
  3. From the dropdown list, select Client Event.
  4. Double-click the Client Event node.
  5. On the pop-up, from the Choose event list, select the transaction event. If you’re not sure of the event’s label in your system, search for transaction.charge.
  6. Click the + where button.
  7. From the Choose parameter dropdown list, select $source.
  8. From the Choose operator dropdown list, select Equal.
  9. In the text field, enter POS.
  10. Confirm by clicking Apply.

2. Send offline transactions to Facebook

Configuration of the Outgoing Integration
Configuration of the Outgoing Integration
  1. On the Client Event node, click the plus icon.
  2. From the dropdown list, select Outgoing integration.
  3. Double-click the Outgoing integration node.
  4. On the pop-up, select the Integrations tab.
  5. From the select custom action dropdown list, choose the outgoing integration you created in the Create an outgoing integration section.
  6. In the Offline Event Set ID, enter the ID of the Offline Event Set.
  7. From the Type of client’s identifier dropdown list, select email.
  8. In the Identifier field, enter the following Jinjava code: {{ client.email | hash("SHA-256") }}
    Tip: You can also select phone instead of an email. In this case, in step 5, from the dropdown list, select PHONE. In step 8, in the Identifier field, enter the following Jinjava code:{{ client.phone | hash("SHA-256") }}
  9. Confirm by clicking Apply.

3. Add the End node

  1. On the Outgoing webhook node, click the plus button.
  2. From the dropdown list, select End.
  3. Save and activate the automation by clicking Save&Run.
  4. Go to your Facebook Ad account, select Facebook Manager > Events Manager to see the events.

Result: After the offline transaction, the automation event is visible on the customer’s card with 200 status. That means that the transaction has successfully been sent to Facebook.

A webhook response with 200 status on a profile of a test customer
A webhook response with the OK status (200) on a customer's profile
๐Ÿ˜•

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

๐Ÿ˜‰

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.