{
  "name": "GA4 Daily Sync - Every 12 Hours",
  "nodes": [
    {
      "parameters": {
        "mode": "everyX",
        "value": 12,
        "unit": "hours",
        "triggerAtHour": 6
      },
      "id": "cron-trigger",
      "name": "Every 12 Hours (6AM & 6PM)",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "command": "python",
        "arguments": "ga4_sync.py",
        "workingDirectory": "C:\\Users\\USER\\marketing-ops-dashboard"
      },
      "id": "execute-ga4-sync",
      "name": "Execute GA4 Sync Script",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "success-condition",
              "leftValue": "={{ $node['Execute GA4 Sync Script'].json.exitCode }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "check-success",
      "name": "Check Execution Success",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "success-message",
              "name": "message",
              "value": "\u2705 GA4 \u6578\u64da\u540c\u6b65\u6210\u529f\u5b8c\u6210",
              "type": "string"
            },
            {
              "id": "success-timestamp",
              "name": "timestamp",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "success-status",
              "name": "status",
              "value": "success",
              "type": "string"
            },
            {
              "id": "success-output",
              "name": "output",
              "value": "={{ $node['Execute GA4 Sync Script'].json.stdout }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "success-data",
      "name": "Success Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        200
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "error-message",
              "name": "message",
              "value": "\u274c GA4 \u6578\u64da\u540c\u6b65\u5931\u6557",
              "type": "string"
            },
            {
              "id": "error-timestamp",
              "name": "timestamp",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "error-status",
              "name": "status",
              "value": "error",
              "type": "string"
            },
            {
              "id": "error-details",
              "name": "error",
              "value": "={{ $node['Execute GA4 Sync Script'].json.stderr }}",
              "type": "string"
            },
            {
              "id": "exit-code",
              "name": "exitCode",
              "value": "={{ $node['Execute GA4 Sync Script'].json.exitCode }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "error-data",
      "name": "Error Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        400
      ]
    },
    {
      "parameters": {
        "content": "## GA4 \u540c\u6b65\u57f7\u884c\u5831\u544a\n\n**\u72c0\u614b**: {{ $json.status === 'success' ? '\u2705 \u6210\u529f' : '\u274c \u5931\u6557' }}\n**\u6642\u9593**: {{ $json.timestamp }}\n**\u8a0a\u606f**: {{ $json.message }}\n\n{{ $json.status === 'success' ? '**\u8f38\u51fa**:\\n```\\n' + $json.output + '\\n```' : '**\u932f\u8aa4\u8a73\u60c5**:\\n```\\n' + $json.error + '\\n```\\n**\u9000\u51fa\u4ee3\u78bc**: ' + $json.exitCode }}\n\n---\n*\u81ea\u52d5\u5316 GA4 \u6578\u64da\u540c\u6b65\u5de5\u4f5c\u6d41\u7a0b*",
        "options": {}
      },
      "id": "format-report",
      "name": "Format Report",
      "type": "n8n-nodes-base.markdown",
      "typeVersion": 1,
      "position": [
        1120,
        300
      ]
    }
  ],
  "connections": {
    "Every 12 Hours (6AM & 6PM)": {
      "main": [
        [
          {
            "node": "Execute GA4 Sync Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute GA4 Sync Script": {
      "main": [
        [
          {
            "node": "Check Execution Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Execution Success": {
      "main": [
        [
          {
            "node": "Success Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Success Data": {
      "main": [
        [
          {
            "node": "Format Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Data": {
      "main": [
        [
          {
            "node": "Format Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "ga4-daily-sync",
  "tags": [
    {
      "createdAt": "2024-01-01T00:00:00.000Z",
      "updatedAt": "2024-01-01T00:00:00.000Z",
      "id": "ga4-automation",
      "name": "GA4 Automation"
    }
  ]
}