{
  "name": "Tinylytics \u2014 Daily Top Paths",
  "nodes": [
    {
      "parameters": {
        "content": "## Tinylytics daily top paths\\n\\n1. Replace `SITE_ID` in the HTTP Request URL with your numeric site id (from the dashboard URL or `GET /api/v1/sites`).\\n2. Replace `REPLACE_WITH_API_KEY` in the Authorization header with a read-only key (`tly-ro-...`) from Account Settings \u2192 API Access.\\n3. Adjust the schedule if needed.\\n4. Connect the summary Set node to Slack, email, Notion, etc.\\n\\nUses `GET /api/v1/sites/:id/hits?grouped=true&group_by=path`. Prefer a daily or hourly schedule \u2014 avoid tight polling.",
        "height": 320,
        "width": 520,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -720,
        -180
      ],
      "id": "5072c881-9fb4-4653-a533-218a3112932b",
      "name": "Setup"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -420,
        80
      ],
      "id": "3a863dc7-bc72-4d7c-8d7d-7630c9e1402c",
      "name": "Every Day 09:00"
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://tinylytics.app/api/v1/sites/SITE_ID/hits",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "grouped",
              "value": "true"
            },
            {
              "name": "group_by",
              "value": "path"
            },
            {
              "name": "start_date",
              "value": "={{ $now.minus({ days: 1 }).format('yyyy-MM-dd') }}"
            },
            {
              "name": "end_date",
              "value": "={{ $now.minus({ days: 1 }).format('yyyy-MM-dd') }}"
            },
            {
              "name": "time_zone",
              "value": "user"
            },
            {
              "name": "per_page",
              "value": "10"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer REPLACE_WITH_API_KEY"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -180,
        80
      ],
      "id": "ea671d31-daf4-454b-bb12-3b472036f0fd",
      "name": "Get Grouped Hits"
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\nconst hits = Array.isArray(response.hits) ? response.hits : [];\nconst lines = hits.slice(0, 10).map((row, index) => {\n  const views = row.views ?? row.hit_count ?? 0;\n  return `${index + 1}. ${row.path || '(unknown)'} \u2014 ${views} views`;\n});\n\nreturn [{\n  json: {\n    start_date: response.filters?.start_date || null,\n    end_date: response.filters?.end_date || null,\n    path_count: hits.length,\n    top_paths_text: lines.length ? lines.join('\\n') : 'No hits for this day.',\n    hits,\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        60,
        80
      ],
      "id": "dbfeef7c-e272-4639-953b-ace9229ad336",
      "name": "Build Summary"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "61750fe0-d690-44b6-94af-eff9ab99b1f3",
              "name": "message",
              "value": "=Top paths for {{ $json.start_date }}\\n\\n{{ $json.top_paths_text }}",
              "type": "string"
            },
            {
              "id": "23e7a932-d694-4674-90e2-0e1efee29873",
              "name": "path_count",
              "value": "={{ $json.path_count }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        80
      ],
      "id": "634a44d8-761d-4e0a-aa17-012ac78e08ca",
      "name": "Format Message"
    },
    {
      "parameters": {
        "content": "## Next step\\n\\nWire Format Message into Slack, email, or a Notion database.\\n\\nOptional: call `GET /api/v1/me` first to validate the API key.",
        "height": 160,
        "width": 320,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        540,
        20
      ],
      "id": "b799f73a-d664-4be9-8d68-d2d47162ca43",
      "name": "Next Step"
    }
  ],
  "pinData": {},
  "connections": {
    "Every Day 09:00": {
      "main": [
        [
          {
            "node": "Get Grouped Hits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Grouped Hits": {
      "main": [
        [
          {
            "node": "Build Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Summary": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}
