{
  "$meta": {
    "package": "@walkeros/web-destination-meta",
    "version": "4.2.1",
    "type": "destination",
    "platform": [
      "web"
    ],
    "docs": "https://www.walkeros.io/docs/destinations/web/meta-pixel",
    "source": "https://github.com/elbwalker/walkerOS/tree/main/packages/web/destinations/meta/src"
  },
  "schemas": {
    "mapping": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {
        "track": {
          "type": "string",
          "enum": [
            "PageView",
            "AddPaymentInfo",
            "AddToCart",
            "AddToWishlist",
            "CompleteRegistration",
            "Contact",
            "CustomizeProduct",
            "Donate",
            "FindLocation",
            "InitiateCheckout",
            "Lead",
            "Purchase",
            "Schedule",
            "Search",
            "StartTrial",
            "SubmitApplication",
            "Subscribe",
            "ViewContent"
          ],
          "description": "Meta Pixel standard event name to send (like PageView or Purchase)"
        },
        "trackCustom": {
          "type": "string",
          "minLength": 1,
          "description": "Custom event name for tracking non-standard events (like NewsletterSignup)"
        }
      },
      "additionalProperties": false
    },
    "settings": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {
        "pixelId": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[0-9]+$",
          "description": "Your Meta Pixel ID from Facebook Business Manager (like 1234567890)"
        }
      },
      "required": [
        "pixelId"
      ],
      "additionalProperties": false
    }
  },
  "examples": {
    "env": {
      "init": {
        "window": {},
        "document": {
          "createElement": {
            "$code": "()=>({src:\"\",async:!1,setAttribute:()=>{},removeAttribute:()=>{}})"
          },
          "head": {
            "appendChild": {
              "$code": "()=>{}"
            }
          }
        }
      },
      "push": {
        "window": {
          "fbq": {
            "$code": "()=>{}"
          },
          "_fbq": {
            "$code": "()=>{}"
          }
        },
        "document": {
          "createElement": {
            "$code": "()=>({src:\"\",async:!1,setAttribute:()=>{},removeAttribute:()=>{}})"
          },
          "head": {
            "appendChild": {
              "$code": "()=>{}"
            }
          }
        }
      },
      "simulation": [
        "call:window.fbq"
      ]
    },
    "step": {
      "addToCart": {
        "title": "Add to cart",
        "description": "A product add event is mapped to the Meta Pixel AddToCart standard event with product contents and value.",
        "in": {
          "name": "product add",
          "data": {
            "id": "ers",
            "name": "Everyday Ruck Snack",
            "color": "black",
            "size": "l",
            "price": 420
          },
          "context": {
            "shopping": [
              "intent",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "us3r",
            "device": "c00k13",
            "session": "s3ss10n"
          },
          "nested": [],
          "consent": {
            "functional": true
          },
          "id": "1700000001-gr0up-1",
          "trigger": "click",
          "entity": "product",
          "action": "add",
          "timestamp": 1700000001,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "collector",
            "schema": "4"
          }
        },
        "mapping": {
          "name": "AddToCart",
          "data": {
            "map": {
              "value": "data.price",
              "currency": {
                "value": "EUR"
              },
              "contents": {
                "set": [
                  {
                    "map": {
                      "id": "data.id",
                      "quantity": {
                        "key": "data.quantity",
                        "value": 1
                      }
                    }
                  }
                ]
              },
              "content_type": {
                "value": "product"
              }
            }
          }
        },
        "out": [
          [
            "fbq",
            "track",
            "AddToCart",
            {
              "currency": "EUR",
              "value": 420,
              "contents": [
                {
                  "id": "ers",
                  "quantity": 1
                }
              ],
              "content_type": "product"
            },
            {
              "eventID": "1700000001-gr0up-1"
            }
          ]
        ]
      },
      "customEventWithTrackCustom": {
        "title": "Custom event",
        "description": "A video complete event is sent as a Meta Pixel trackCustom call with a custom event name and parameters.",
        "in": {
          "name": "video complete",
          "data": {
            "video_id": "v1d30",
            "duration": 120
          },
          "context": {
            "dev": [
              "test",
              1
            ]
          },
          "globals": {
            "lang": "elb"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "us3r",
            "device": "c00k13",
            "session": "s3ss10n"
          },
          "nested": [
            {
              "entity": "child",
              "data": {
                "is": "subordinated"
              }
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "1700000005-gr0up-1",
          "trigger": "test",
          "entity": "video",
          "action": "complete",
          "timestamp": 1700000005,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "collector",
            "schema": "4"
          }
        },
        "mapping": {
          "settings": {
            "trackCustom": "VideoComplete"
          },
          "data": {
            "map": {
              "video_id": "data.video_id",
              "duration": "data.duration"
            }
          }
        },
        "out": [
          [
            "fbq",
            "trackCustom",
            "VideoComplete",
            {
              "video_id": "v1d30",
              "duration": 120
            },
            {
              "eventID": "1700000005-gr0up-1"
            }
          ]
        ]
      },
      "init": {
        "title": "Pixel init",
        "description": "The destination loads the Meta Pixel script and initializes it with the configured pixelId.",
        "in": {
          "loadScript": true,
          "settings": {
            "pixelId": "1234567890"
          }
        },
        "out": [
          [
            "fbq",
            "init",
            "1234567890"
          ]
        ]
      },
      "initiateCheckout": {
        "title": "Initiate checkout",
        "description": "A cart view event is mapped to the Meta Pixel InitiateCheckout standard event with value and product contents.",
        "in": {
          "name": "cart view",
          "data": {
            "currency": "EUR",
            "value": 840
          },
          "context": {
            "shopping": [
              "cart",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "us3r",
            "device": "c00k13",
            "session": "s3ss10n"
          },
          "nested": [
            {
              "entity": "product",
              "data": {
                "id": "ers",
                "name": "Everyday Ruck Snack",
                "color": "black",
                "size": "l",
                "price": 420,
                "quantity": 2
              },
              "context": {
                "shopping": [
                  "cart",
                  0
                ]
              },
              "nested": []
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "1700000003-gr0up-1",
          "trigger": "load",
          "entity": "cart",
          "action": "view",
          "timestamp": 1700000003,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "collector",
            "schema": "4"
          }
        },
        "mapping": {
          "name": "InitiateCheckout",
          "data": {
            "map": {
              "value": "data.value",
              "currency": {
                "value": "EUR"
              },
              "contents": {
                "loop": [
                  "nested",
                  {
                    "condition": {
                      "$code": "t=>f(t)&&\"product\"===t.entity"
                    },
                    "map": {
                      "id": "data.id",
                      "quantity": {
                        "key": "data.quantity",
                        "value": 1
                      }
                    }
                  }
                ]
              },
              "num_items": {
                "fn": {
                  "$code": "t=>t.nested.filter(t=>\"product\"===t.entity).length"
                }
              }
            }
          }
        },
        "out": [
          [
            "fbq",
            "track",
            "InitiateCheckout",
            {
              "currency": "EUR",
              "value": 840,
              "contents": [
                {
                  "id": "ers",
                  "quantity": 2
                }
              ],
              "num_items": 1
            },
            {
              "eventID": "1700000003-gr0up-1"
            }
          ]
        ]
      },
      "pageView": {
        "title": "Page view",
        "description": "A page view event is forwarded to Meta Pixel as the PageView standard event with no extra parameters.",
        "in": {
          "name": "page view",
          "data": {
            "domain": "www.example.com",
            "title": "walkerOS documentation",
            "referrer": "https://www.walkeros.io/",
            "search": "?foo=bar",
            "hash": "#hash",
            "id": "/docs/"
          },
          "context": {
            "dev": [
              "test",
              1
            ]
          },
          "globals": {
            "pagegroup": "docs"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "us3r",
            "device": "c00k13",
            "session": "s3ss10n"
          },
          "nested": [
            {
              "entity": "child",
              "data": {
                "is": "subordinated"
              }
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "1700000004-gr0up-1",
          "trigger": "load",
          "entity": "page",
          "action": "view",
          "timestamp": 1700000004,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "collector",
            "schema": "4"
          }
        },
        "out": [
          [
            "fbq",
            "track",
            "PageView",
            {},
            {
              "eventID": "1700000004-gr0up-1"
            }
          ]
        ]
      },
      "purchase": {
        "title": "Purchase",
        "description": "An order complete event is mapped to the Meta Pixel Purchase standard event with value, currency, and product contents.",
        "in": {
          "name": "order complete",
          "data": {
            "id": "0rd3r1d",
            "currency": "EUR",
            "shipping": 5.22,
            "taxes": 73.76,
            "total": 555
          },
          "context": {
            "shopping": [
              "complete",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "us3r",
            "device": "c00k13",
            "session": "s3ss10n"
          },
          "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": "1700000000-gr0up-1",
          "trigger": "load",
          "entity": "order",
          "action": "complete",
          "timestamp": 1700000000,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "collector",
            "schema": "4"
          }
        },
        "mapping": {
          "name": "Purchase",
          "data": {
            "map": {
              "value": "data.total",
              "currency": {
                "value": "EUR"
              },
              "contents": {
                "loop": [
                  "nested",
                  {
                    "condition": {
                      "$code": "t=>f(t)&&\"product\"===t.entity"
                    },
                    "map": {
                      "id": "data.id",
                      "quantity": {
                        "key": "data.quantity",
                        "value": 1
                      }
                    }
                  }
                ]
              },
              "content_type": {
                "value": "product"
              },
              "num_items": {
                "fn": {
                  "$code": "t=>t.nested.filter(t=>\"product\"===t.entity).length"
                }
              }
            }
          }
        },
        "out": [
          [
            "fbq",
            "track",
            "Purchase",
            {
              "value": 555,
              "currency": "EUR",
              "contents": [
                {
                  "id": "ers",
                  "quantity": 1
                },
                {
                  "id": "cc",
                  "quantity": 1
                }
              ],
              "content_type": "product",
              "num_items": 2
            },
            {
              "eventID": "1700000000-gr0up-1"
            }
          ]
        ]
      },
      "viewContent": {
        "title": "View content",
        "description": "A product view event is mapped to the Meta Pixel ViewContent standard event with single-product contents.",
        "in": {
          "name": "product view",
          "data": {
            "id": "ers",
            "name": "Everyday Ruck Snack",
            "color": "black",
            "size": "l",
            "price": 420
          },
          "context": {
            "shopping": [
              "detail",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "us3r",
            "device": "c00k13",
            "session": "s3ss10n"
          },
          "nested": [],
          "consent": {
            "functional": true
          },
          "id": "1700000002-gr0up-1",
          "trigger": "load",
          "entity": "product",
          "action": "view",
          "timestamp": 1700000002,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "collector",
            "schema": "4"
          }
        },
        "mapping": {
          "name": "ViewContent",
          "data": {
            "map": {
              "value": "data.price",
              "currency": {
                "value": "EUR"
              },
              "content_type": {
                "value": "product"
              },
              "contents": {
                "set": [
                  {
                    "map": {
                      "id": "data.id",
                      "quantity": {
                        "key": "data.quantity",
                        "value": 1
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "out": [
          [
            "fbq",
            "track",
            "ViewContent",
            {
              "currency": "EUR",
              "value": 420,
              "contents": [
                {
                  "id": "ers",
                  "quantity": 1
                }
              ],
              "content_type": "product"
            },
            {
              "eventID": "1700000002-gr0up-1"
            }
          ]
        ]
      }
    }
  }
}