{
  "name": "Offline conversion sync: Stripe to Meta (New Theory template)",
  "nodes": [
    {
      "parameters": {
        "content": "## Offline conversion sync: n8n starter (Stripe to Meta)\nFree template from New Theory (newtheory.marketing). Built from our playbook records. It is not an official n8n, HubSpot or Zapier template. Every credential is a placeholder: connect your own before you turn it on.\n\n**Fill in, in this order**\n1. **Stripe invoice paid**: connect Stripe and set a Signature Secret on the credential so forged or stale requests get a 401.\n2. At signup, write fbc, client_user_agent, signup_url and ad_consent into the subscription's metadata (subscription_data.metadata in Checkout) so they ride on every invoice.\n3. **Send Purchase to Meta**: replace REPLACE_WITH_DATASET_ID and add a Query Auth credential named access_token with the token from Events Manager. Set the Graph API version you use.\n4. Test first: add \"test_event_code\" to the body, check the Test events tab, then remove it.\n5. **Log failed events**: connect Google Sheets and make a Failed tab.\n\nGoogle Ads offline imports now go through the Data Manager API, so this file covers Meta. Use the HubSpot or Zapier route in the guide for Google.",
        "height": 440,
        "width": 600,
        "color": 4
      },
      "id": "b34c50d9-13eb-49fc-a081-cde4184317ef",
      "name": "Start here",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -60
      ]
    },
    {
      "parameters": {
        "events": [
          "invoice.paid"
        ]
      },
      "id": "6bebb314-3adc-4dd9-ac76-e86d0654e2af",
      "name": "Stripe invoice paid",
      "type": "n8n-nodes-base.stripeTrigger",
      "typeVersion": 1,
      "position": [
        0,
        520
      ],
      "webhookId": "805e3f83-ea7a-421d-a508-8550d5aefc3a",
      "credentials": {
        "stripeApi": {
          "id": "replace-me",
          "name": "Stripe (connect yours)"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "e280546f-462f-42c8-ab41-9cfa67f60d3a",
              "leftValue": "={{ $json.data.object.billing_reason }}",
              "rightValue": "subscription_create",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "559328f4-44cd-41bc-afce-13e4f1bbd8e0",
              "leftValue": "={{ $json.data.object.subscription_details?.metadata?.ad_consent }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "16d89cfb-eb6f-4c0f-a885-431583a9bbb5",
      "name": "New customer with consent?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        220,
        520
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2dc2db42-4fa2-4b32-a430-f32f30aac23d",
              "name": "email_clean",
              "value": "={{ String($json.data.object.customer_email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "8de39f54-865c-46b6-ac8c-6640e0cb670d",
              "name": "event_id",
              "value": "={{ $json.data.object.id }}",
              "type": "string"
            },
            {
              "id": "f68213b8-c371-4123-a63f-c7733fde79ae",
              "name": "event_time",
              "value": "={{ $json.data.object.status_transitions?.paid_at || Math.floor(Date.now() / 1000) }}",
              "type": "number"
            },
            {
              "id": "c75f825b-c60d-46e7-a6cf-3ac2867d0f06",
              "name": "value",
              "value": "={{ $json.data.object.amount_paid / 100 }}",
              "type": "number"
            },
            {
              "id": "12e8d0ea-ba2c-4d96-ac95-380640ab4bf4",
              "name": "currency",
              "value": "={{ String($json.data.object.currency || '').toUpperCase() }}",
              "type": "string"
            },
            {
              "id": "3a69f7a3-809d-4d6f-addd-abd7333f9467",
              "name": "fbc",
              "value": "={{ $json.data.object.subscription_details?.metadata?.fbc || '' }}",
              "type": "string"
            },
            {
              "id": "14c3b7b0-bafc-4df0-aff5-4426a56fdc71",
              "name": "client_user_agent",
              "value": "={{ $json.data.object.subscription_details?.metadata?.client_user_agent || '' }}",
              "type": "string"
            },
            {
              "id": "9d89fa30-a57c-4d56-ad7d-f3eee536b05c",
              "name": "event_source_url",
              "value": "={{ $json.data.object.subscription_details?.metadata?.signup_url || '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "71492b17-cea9-4c67-ae69-940ef80a95c5",
      "name": "Shape the event",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        440,
        500
      ]
    },
    {
      "parameters": {
        "type": "SHA256",
        "value": "={{ $json.email_clean }}",
        "dataPropertyName": "hashed_email",
        "encoding": "hex"
      },
      "id": "b5d307c8-1ef3-4334-a9d2-ee928703e814",
      "name": "Hash the email",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        660,
        500
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/REPLACE_WITH_DATASET_ID/events",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"data\": [\n    {\n      \"event_name\": \"Purchase\",\n      \"event_time\": {{ $('Shape the event').item.json.event_time }},\n      \"event_id\": \"{{ $('Shape the event').item.json.event_id }}\",\n      \"action_source\": \"website\",\n      \"event_source_url\": \"{{ $('Shape the event').item.json.event_source_url }}\",\n      \"user_data\": {\n        \"em\": [\"{{ $json.hashed_email }}\"],\n        \"fbc\": \"{{ $('Shape the event').item.json.fbc }}\",\n        \"client_user_agent\": \"{{ $('Shape the event').item.json.client_user_agent }}\"\n      },\n      \"custom_data\": { \"value\": {{ $('Shape the event').item.json.value }}, \"currency\": \"{{ $('Shape the event').item.json.currency }}\" }\n    }\n  ]\n}",
        "options": {}
      },
      "id": "7dccfad7-8c5f-448e-a7b2-b87d8d87785e",
      "name": "Send Purchase to Meta",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        500
      ],
      "credentials": {
        "httpQueryAuth": {
          "id": "replace-me",
          "name": "Meta Conversions API (Query Auth: access_token)"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c7ea9ad7-ed77-4449-ae9a-2fae88e32594",
              "name": "event_id",
              "value": "={{ $('Shape the event').item.json.event_id }}",
              "type": "string"
            },
            {
              "id": "b31d5b38-1096-45a3-adc1-e07e977813d1",
              "name": "failed_at",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            },
            {
              "id": "0a28972e-dfff-4c36-ac8a-1e832bd90079",
              "name": "error",
              "value": "={{ JSON.stringify($json.error || $json) }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "77a8a2b1-c0e4-451d-aae7-f57ddcb9c885",
      "name": "Failed event row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1100,
        640
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_YOUR_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Failed",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "0881f87a-13d9-420c-a5ce-898452db47ed",
      "name": "Log failed events",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1320,
        640
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "replace-me",
          "name": "Google Sheets (connect yours)"
        }
      }
    },
    {
      "parameters": {
        "content": "### Keep the loop honest\n- Never hash fbc. Send it exactly as stored, case and all.\n- Meta rejects a batch with any event older than 7 days, so resend failed rows inside that window.\n- event_id is the invoice ID, so Meta can drop a duplicate if the pixel also fired.\n- Stripe amounts are in the minor unit: 1000 is 10 USD. The Shape node divides by 100.\n- Only customers who said yes to ad data sharing pass the filter.",
        "height": 260,
        "width": 480,
        "color": 3
      },
      "id": "68e1b07d-4a2f-44b5-ad07-5cc78c1e56c0",
      "name": "Rules",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        860,
        140
      ]
    }
  ],
  "connections": {
    "Stripe invoice paid": {
      "main": [
        [
          {
            "node": "New customer with consent?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New customer with consent?": {
      "main": [
        [
          {
            "node": "Shape the event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape the event": {
      "main": [
        [
          {
            "node": "Hash the email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hash the email": {
      "main": [
        [
          {
            "node": "Send Purchase to Meta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Purchase to Meta": {
      "main": [
        [],
        [
          {
            "node": "Failed event row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Failed event row": {
      "main": [
        [
          {
            "node": "Log failed events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
