{
  "name": "Google Ads + YouTube Ads Pull via tap-google-ads (google-ads-pull)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      },
      "id": "schedule-trigger-gads",
      "name": "Schedule Trigger (6h)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "command": "=bash {{ $env.SINGER_SCRIPT_DIR || '/opt/walter-os/singer' }}/run-tap.sh google_ads 2>&1"
      },
      "id": "run-tap-google-ads",
      "name": "Run tap-google-ads",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        460,
        300
      ],
      "notes": "Runs Singer tap-google-ads with state management. Output piped through singer_to_analytics.py \u2192 Postgres. Prereq: GOOGLE_ADS_DEVELOPER_TOKEN + OAuth (V-prereq-1, 3-5 day approval)."
    },
    {
      "parameters": {
        "jsCode": "// Check exit code and format result\nconst stdout = $json.stdout || '';\nconst stderr = $json.stderr || '';\nconst exitCode = $json.exitCode || 0;\n\nif (exitCode !== 0) {\n  // Don't throw \u2014 let it pass through to Telegram alert\n  return [{ json: { success: false, error: stderr, tap: 'tap-google-ads' } }];\n}\n\n// Parse counts from singer_to_analytics output\nconst match = (stdout + stderr).match(/Done: (.+)/);\nreturn [{ json: { success: true, output: match?.[1] || 'ok', tap: 'tap-google-ads' } }];"
      },
      "id": "parse-tap-result",
      "name": "Parse Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "id": "check-success",
      "name": "Success?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "message": "=[tap-google-ads] ERROR: {{ $json.error }}",
        "additionalFields": {
          "chat_id": "={{ $env.WALTER_TELEGRAM_CHAT_ID }}"
        }
      },
      "id": "telegram-error",
      "name": "Telegram Error Alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1120,
        420
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    }
  ],
  "connections": {
    "Schedule Trigger (6h)": {
      "main": [
        [
          {
            "node": "Run tap-google-ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run tap-google-ads": {
      "main": [
        [
          {
            "node": "Parse Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Result": {
      "main": [
        [
          {
            "node": "Success?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Success?": {
      "main": [
        [],
        [
          {
            "node": "Telegram Error Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "tags": [
    "devrel-analytics",
    "tier-2",
    "google-ads",
    "youtube-ads",
    "singer"
  ],
  "versionId": "v1",
  "notes": "Phase V Part B \u2014 AC-6. INACTIVE until Google Ads Developer Token approved (V-prereq-1). tap-google-ads also covers YouTube Ads metrics. Incremental sync via state file at ~/.config/walter-os/singer-state/google-ads.json. See docs/specs/devrel-analytics-stack.md."
}