{
  "$meta": {
    "package": "@walkeros/server-destination-meta",
    "version": "4.2.1",
    "type": "destination",
    "platform": [
      "server"
    ],
    "docs": "https://www.walkeros.io/docs/destinations/server/meta-capi",
    "source": "https://github.com/elbwalker/walkerOS/tree/main/packages/server/destinations/meta/src"
  },
  "schemas": {
    "mapping": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {},
      "additionalProperties": false
    },
    "settings": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {
        "accessToken": {
          "type": "string",
          "minLength": 1,
          "description": "Meta access token for Conversions API authentication (like your_access_token)"
        },
        "pixelId": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "description": "Meta Pixel ID from your Facebook Business account (like 1234567890)"
        },
        "action_source": {
          "type": "string",
          "enum": [
            "email",
            "website",
            "app",
            "phone_call",
            "chat",
            "physical_store",
            "system_generated",
            "business_messaging",
            "other"
          ],
          "description": "Source of the event (website, app, phone_call, etc.) (like website)"
        },
        "doNotHash": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Array of user_data fields that should not be hashed (like ['client_ip_address', 'client_user_agent'])"
        },
        "test_event_code": {
          "type": "string",
          "description": "Test event code for debugging Meta Conversions API events (like TEST12345)"
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Custom URL for Meta Conversions API endpoint (like https://graph.facebook.com/v17.0)"
        },
        "user_data": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "type": "string"
          },
          "description": "Mapping configuration for user data fields (like { email: 'user.email', phone: 'user.phone' })"
        }
      },
      "required": [
        "accessToken",
        "pixelId"
      ],
      "additionalProperties": false
    }
  },
  "examples": {
    "env": {
      "push": {
        "sendServer": {
          "$code": "async function(e,t,a){return{ok:!0,data:{events_received:1,messages:[],fbtrace_id:\"mock-trace-id\"}}}"
        }
      },
      "simulation": [
        "sendServer"
      ]
    },
    "step": {
      "lead": {
        "title": "Form submit",
        "description": "A form submission is forwarded to Meta CAPI as a custom event with the event source URL.",
        "in": {
          "name": "form submit",
          "data": {
            "type": "newsletter"
          },
          "context": {
            "dev": [
              "test",
              1
            ]
          },
          "globals": {
            "lang": "elb"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "email": "user@example.com"
          },
          "nested": [
            {
              "entity": "child",
              "data": {
                "is": "subordinated"
              }
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "c1d2e3f4a5b60002",
          "trigger": "test",
          "entity": "form",
          "action": "submit",
          "timestamp": 1700000901,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "browser",
            "platform": "web",
            "url": "https://example.com"
          }
        },
        "out": [
          [
            "sendServer",
            "https://graph.facebook.com/v22.0/p1x3l1d/events",
            "{\"data\":[{\"event_name\":\"form submit\",\"event_id\":\"c1d2e3f4a5b60002\",\"event_time\":1700001,\"action_source\":\"website\",\"user_data\":{},\"event_source_url\":\"https://example.com\"}]}",
            {
              "headers": {
                "Authorization": "Bearer s3cr3t"
              }
            }
          ]
        ]
      },
      "purchase": {
        "title": "Purchase",
        "description": "A completed order is sent to the Meta Conversions API as a Purchase event with value, currency, and contents.",
        "in": {
          "name": "order complete",
          "data": {
            "id": "ORD-300",
            "total": 249.99,
            "currency": "EUR"
          },
          "context": {
            "shopping": [
              "complete",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "user-123",
            "device": "device-456"
          },
          "nested": [
            {
              "entity": "product",
              "data": {
                "id": "SKU-A1",
                "price": 129.99,
                "quantity": 2
              }
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "c1d2e3f4a5b60001",
          "trigger": "load",
          "entity": "order",
          "action": "complete",
          "timestamp": 1700000900,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "browser",
            "platform": "web",
            "url": "https://shop.example.com"
          }
        },
        "mapping": {
          "name": "Purchase",
          "data": {
            "map": {
              "order_id": "data.id",
              "currency": {
                "key": "data.currency",
                "value": "EUR"
              },
              "value": "data.total",
              "contents": {
                "loop": [
                  "nested",
                  {
                    "condition": {
                      "$code": "e=>y(e)&&\"product\"===e.entity"
                    },
                    "map": {
                      "id": "data.id",
                      "item_price": "data.price",
                      "quantity": {
                        "key": "data.quantity",
                        "value": 1
                      }
                    }
                  }
                ]
              },
              "num_items": {
                "fn": {
                  "$code": "e=>e.nested.filter(e=>\"product\"===e.entity).length"
                }
              }
            }
          }
        },
        "out": [
          [
            "sendServer",
            "https://graph.facebook.com/v22.0/p1x3l1d/events",
            "{\"data\":[{\"event_name\":\"Purchase\",\"event_id\":\"c1d2e3f4a5b60001\",\"event_time\":1700001,\"action_source\":\"website\",\"order_id\":\"ORD-300\",\"currency\":\"EUR\",\"value\":249.99,\"contents\":[{\"id\":\"SKU-A1\",\"item_price\":129.99,\"quantity\":2}],\"num_items\":1,\"user_data\":{},\"event_source_url\":\"https://shop.example.com\"}]}",
            {
              "headers": {
                "Authorization": "Bearer s3cr3t"
              }
            }
          ]
        ]
      },
      "purchaseWithClickAttribution": {
        "title": "Purchase with fbclid",
        "description": "A purchase is sent to Meta CAPI with an external_id and a formatted fbc click id for ads attribution.",
        "in": {
          "name": "order complete",
          "data": {
            "id": "ORD-700",
            "total": 89.99,
            "currency": "USD"
          },
          "context": {
            "fbclid": [
              "abc123xyz",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "cust-42"
          },
          "nested": [
            {
              "entity": "product",
              "data": {
                "id": "ers",
                "name": "Everyday Ruck Snack",
                "color": "black",
                "size": "l",
                "price": 420
              },
              "context": {
                "shopping": [
                  "complete",
                  0
                ]
              },
              "nested": []
            },
            {
              "entity": "product",
              "data": {
                "id": "cc",
                "name": "Cool Cap",
                "size": "one size",
                "price": 42
              },
              "context": {
                "shopping": [
                  "complete",
                  0
                ]
              },
              "nested": []
            },
            {
              "entity": "gift",
              "data": {
                "name": "Surprise"
              },
              "context": {
                "shopping": [
                  "complete",
                  0
                ]
              },
              "nested": []
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "c1d2e3f4a5b60003",
          "trigger": "load",
          "entity": "order",
          "action": "complete",
          "timestamp": 1700000902,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "browser",
            "platform": "web",
            "url": "https://shop.example.com"
          }
        },
        "mapping": {
          "name": "Purchase",
          "data": {
            "map": {
              "currency": {
                "key": "data.currency",
                "value": "EUR"
              },
              "value": "data.total",
              "order_id": "data.id",
              "user_data": {
                "map": {
                  "external_id": "user.id",
                  "fbclid": "context.fbclid"
                }
              }
            }
          }
        },
        "out": [
          [
            "sendServer",
            "https://graph.facebook.com/v22.0/p1x3l1d/events",
            "{\"data\":[{\"event_name\":\"Purchase\",\"event_id\":\"c1d2e3f4a5b60003\",\"event_time\":1700001,\"action_source\":\"website\",\"currency\":\"USD\",\"value\":89.99,\"order_id\":\"ORD-700\",\"user_data\":{\"external_id\":\"8a3c5a67cad508582b5edf6b8352cea3ffbad7f44812c1a736b4444c0f5746aa\",\"fbc\":\"fb.1.1700000902.abc123xyz,0\"},\"event_source_url\":\"https://shop.example.com\"}]}",
            {
              "headers": {
                "Authorization": "Bearer s3cr3t"
              }
            }
          ]
        ]
      }
    }
  }
}