{
  "$meta": {
    "package": "@walkeros/server-destination-datamanager",
    "version": "4.2.1",
    "type": "destination",
    "platform": [
      "server"
    ],
    "docs": "https://www.walkeros.io/docs/destinations/server/datamanager",
    "source": "https://github.com/elbwalker/walkerOS/tree/main/packages/server/destinations/datamanager/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": {
        "credentials": {
          "description": "Service account credentials (client_email + private_key). Recommended for serverless environments. (deprecated: use config.credentials)",
          "type": "object",
          "properties": {
            "client_email": {
              "type": "string",
              "format": "email",
              "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
              "description": "Service account email"
            },
            "private_key": {
              "type": "string",
              "minLength": 1,
              "description": "Service account private key (PEM format)"
            }
          },
          "required": [
            "client_email",
            "private_key"
          ],
          "additionalProperties": false,
          "title": "credentials"
        },
        "keyFilename": {
          "description": "Path to service account JSON file. For local development or environments with filesystem access.",
          "type": "string"
        },
        "scopes": {
          "description": "OAuth scopes for Data Manager API. Defaults to datamanager scope.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "destinations": {
          "minItems": 1,
          "maxItems": 10,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "operatingAccount": {
                "type": "object",
                "properties": {
                  "accountId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Account ID (e.g., \"123-456-7890\" for Google Ads)"
                  },
                  "accountType": {
                    "type": "string",
                    "enum": [
                      "GOOGLE_ADS",
                      "DISPLAY_VIDEO_ADVERTISER",
                      "DISPLAY_VIDEO_PARTNER",
                      "GOOGLE_ANALYTICS_PROPERTY"
                    ],
                    "description": "Type of account"
                  }
                },
                "required": [
                  "accountId",
                  "accountType"
                ],
                "additionalProperties": false,
                "description": "Operating account details"
              },
              "productDestinationId": {
                "type": "string",
                "minLength": 1,
                "description": "Product-specific destination ID (conversion action or user list)"
              }
            },
            "required": [
              "operatingAccount",
              "productDestinationId"
            ],
            "additionalProperties": false
          },
          "description": "Array of destination accounts and conversion actions/user lists (max 10)"
        },
        "eventSource": {
          "default": "WEB",
          "description": "Event source for all events. Defaults to WEB. Values: WEB, APP, IN_STORE, PHONE, OTHER",
          "type": "string",
          "enum": [
            "WEB",
            "APP",
            "IN_STORE",
            "PHONE",
            "OTHER"
          ]
        },
        "batchSize": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2000,
          "description": "Maximum number of events to batch before sending (max 2000, like 100)"
        },
        "batchInterval": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991,
          "description": "Time in milliseconds to wait before auto-flushing batch (like 5000)"
        },
        "validateOnly": {
          "type": "boolean",
          "description": "If true, validate request without ingestion (testing mode)"
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Override API endpoint for testing (like https://datamanager.googleapis.com/v1)"
        },
        "consent": {
          "type": "object",
          "properties": {
            "adUserData": {
              "type": "string",
              "enum": [
                "CONSENT_GRANTED",
                "CONSENT_DENIED"
              ],
              "description": "Consent for data collection and use"
            },
            "adPersonalization": {
              "type": "string",
              "enum": [
                "CONSENT_GRANTED",
                "CONSENT_DENIED"
              ],
              "description": "Consent for ad personalization"
            }
          },
          "additionalProperties": false,
          "description": "Request-level consent for all events",
          "title": "consent"
        },
        "testEventCode": {
          "type": "string",
          "description": "Test event code for debugging (like TEST12345)"
        },
        "logLevel": {
          "type": "string",
          "enum": [
            "debug",
            "info",
            "warn",
            "error",
            "none"
          ],
          "description": "Log level for debugging (debug shows all API calls)"
        },
        "userData": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {},
          "description": "Guided helper: User data mapping for all events (like { email: 'user.id', phone: 'data.phone' })"
        },
        "userId": {
          "description": "Guided helper: First-party user ID for all events (like 'user.id')"
        },
        "clientId": {
          "description": "Guided helper: GA4 client ID for all events (like 'user.device')"
        },
        "appInstanceId": {
          "description": "Guided helper: GA4 app instance ID (Firebase) for all events (like 'user.appInstanceId')"
        },
        "sessionAttributes": {
          "description": "Guided helper: Privacy-safe attribution for all events (like 'context.sessionAttributes')"
        },
        "consentAdUserData": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "boolean"
            }
          ],
          "description": "Consent mapping: Field name from event.consent (like 'marketing') or static boolean value"
        },
        "consentAdPersonalization": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "boolean"
            }
          ],
          "description": "Consent mapping: Field name from event.consent (like 'targeting') or static boolean value"
        }
      },
      "required": [
        "destinations"
      ],
      "additionalProperties": false
    }
  },
  "examples": {
    "env": {
      "push": {
        "fetch": {
          "$code": "async function(){return{ok:!0,status:200,json:async()=>({requestId:\"mock-request-id\",validationErrors:[]}),text:async()=>\"\"}}"
        },
        "authClient": {
          "getAccessToken": {
            "$code": "async()=>({token:\"ya29.c.test_token\"})"
          }
        }
      },
      "simulation": [
        "fetch"
      ]
    },
    "step": {
      "ga4PageView": {
        "title": "Page view",
        "description": "A page view is sent to Data Manager as a page_view event tied to the walker user id.",
        "in": {
          "name": "page view",
          "data": {
            "title": "Pricing",
            "url": "https://example.com/pricing"
          },
          "context": {
            "dev": [
              "test",
              1
            ]
          },
          "globals": {
            "pagegroup": "docs"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "visitor-55"
          },
          "nested": [
            {
              "entity": "child",
              "data": {
                "is": "subordinated"
              }
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "ev-1700000902000",
          "trigger": "load",
          "entity": "page",
          "action": "view",
          "timestamp": 1700000902000,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "express",
            "platform": "server"
          }
        },
        "mapping": {
          "name": "page_view",
          "data": {
            "map": {
              "transactionId": "id",
              "eventName": {
                "value": "page_view"
              },
              "userId": "user.id"
            }
          }
        },
        "out": [
          [
            "fetch",
            "https://datamanager.googleapis.com/v1/events:ingest",
            {
              "method": "POST",
              "headers": {
                "Authorization": "Bearer ya29.c.test_token",
                "Content-Type": "application/json"
              },
              "body": "{\"events\":[{\"eventTimestamp\":\"2023-11-14T22:28:22.000Z\",\"transactionId\":\"ev-1700000902000\",\"userId\":\"visitor-55\",\"eventName\":\"page_view\",\"eventSource\":\"WEB\"}],\"destinations\":[{\"operatingAccount\":{\"accountId\":\"123-456-7890\",\"accountType\":\"GOOGLE_ADS\"},\"productDestinationId\":\"AW-CONVERSION-123\"}],\"encoding\":\"HEX\"}"
            }
          ]
        ]
      },
      "lead": {
        "title": "Lead",
        "description": "A demo request form submission is sent to Data Manager as a generate_lead conversion with a hashed email.",
        "in": {
          "name": "form submit",
          "data": {
            "type": "demo-request"
          },
          "context": {
            "dev": [
              "test",
              1
            ]
          },
          "globals": {
            "lang": "elb"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "email": "prospect@example.com"
          },
          "nested": [
            {
              "entity": "child",
              "data": {
                "is": "subordinated"
              }
            }
          ],
          "consent": {
            "functional": true
          },
          "id": "ev-1700000901000",
          "trigger": "test",
          "entity": "form",
          "action": "submit",
          "timestamp": 1700000901000,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "express",
            "platform": "server"
          }
        },
        "mapping": {
          "name": "generate_lead",
          "data": {
            "map": {
              "transactionId": "id",
              "eventName": {
                "value": "generate_lead"
              },
              "conversionValue": {
                "value": 10
              },
              "currency": {
                "value": "USD"
              },
              "email": "user.email"
            }
          }
        },
        "out": [
          [
            "fetch",
            "https://datamanager.googleapis.com/v1/events:ingest",
            {
              "method": "POST",
              "headers": {
                "Authorization": "Bearer ya29.c.test_token",
                "Content-Type": "application/json"
              },
              "body": "{\"events\":[{\"eventTimestamp\":\"2023-11-14T22:28:21.000Z\",\"transactionId\":\"ev-1700000901000\",\"userData\":{\"userIdentifiers\":[{\"emailAddress\":\"395ec5f334be0ab5b28568a1e7f6ed5ea80e443fb1ce3d803340586a3df46642\"}]},\"conversionValue\":10,\"currency\":\"USD\",\"eventName\":\"generate_lead\",\"eventSource\":\"WEB\"}],\"destinations\":[{\"operatingAccount\":{\"accountId\":\"123-456-7890\",\"accountType\":\"GOOGLE_ADS\"},\"productDestinationId\":\"AW-CONVERSION-123\"}],\"encoding\":\"HEX\"}"
            }
          ]
        ]
      },
      "purchase": {
        "title": "Purchase",
        "description": "A completed order is posted to Google Data Manager as a purchase conversion with hashed user identifiers.",
        "in": {
          "name": "order complete",
          "data": {
            "id": "ORD-600",
            "total": 149.99,
            "currency": "EUR"
          },
          "context": {
            "shopping": [
              "complete",
              0
            ]
          },
          "globals": {
            "pagegroup": "shop"
          },
          "custom": {
            "completely": "random"
          },
          "user": {
            "id": "user-abc",
            "email": "buyer@example.com"
          },
          "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": "ev-1700000900000",
          "trigger": "load",
          "entity": "order",
          "action": "complete",
          "timestamp": 1700000900000,
          "timing": 3.14,
          "source": {
            "count": 1,
            "trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
            "type": "express",
            "platform": "server"
          }
        },
        "mapping": {
          "name": "purchase",
          "data": {
            "map": {
              "transactionId": "data.id",
              "conversionValue": "data.total",
              "currency": {
                "key": "data.currency",
                "value": "USD"
              },
              "eventName": {
                "value": "purchase"
              },
              "userId": "user.id",
              "email": "user.email"
            }
          }
        },
        "out": [
          [
            "fetch",
            "https://datamanager.googleapis.com/v1/events:ingest",
            {
              "method": "POST",
              "headers": {
                "Authorization": "Bearer ya29.c.test_token",
                "Content-Type": "application/json"
              },
              "body": "{\"events\":[{\"eventTimestamp\":\"2023-11-14T22:28:20.000Z\",\"transactionId\":\"ORD-600\",\"userId\":\"user-abc\",\"userData\":{\"userIdentifiers\":[{\"emailAddress\":\"6a6c26195c3682faa816966af789717c3bfa834eee6c599d667d2b3429c27cfd\"}]},\"conversionValue\":149.99,\"currency\":\"EUR\",\"eventName\":\"purchase\",\"eventSource\":\"WEB\"}],\"destinations\":[{\"operatingAccount\":{\"accountId\":\"123-456-7890\",\"accountType\":\"GOOGLE_ADS\"},\"productDestinationId\":\"AW-CONVERSION-123\"}],\"encoding\":\"HEX\"}"
            }
          ]
        ]
      }
    }
  }
}