{
  "name": "Weekly report: who runs sponsored ads on your Amazon keywords",
  "nodes": [
    {
      "id": "47bfe011-c562-5470-a9b3-4224ce36120d",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -720,
        0
      ],
      "parameters": {
        "content": "## Weekly report: who runs sponsored ads on your Amazon keywords\n\n### How it works\nFor Amazon brands, agencies and sellers checking who pays to appear on their search terms. Every Monday at 08:00, the workflow runs the [Amazon Search Results Scraper](https://apify.com/aurelix/amazon-product-search) Actor on Apify and runs Amazon searches for your keywords and appends one row per sponsored product (keyword, position, a brand guess from the first word of the title, ASIN, title, price, rating) to a Google Sheet.\n\n### Setup\n1. Install the **Apify** node (verified community node: on n8n Cloud search *Apify* in the nodes panel and click Install; self-hosted: Settings > Community nodes > `@apify/n8n-nodes-apify`). Create an **Apify API** credential with your API token (Apify Console > Settings > API & Integrations) and select it on the Apify node. Tested with `@apify/n8n-nodes-apify` 0.9.0 on n8n 2.46; install guide: https://docs.apify.com/platform/integrations/n8n\n2. Create a **Google Sheets OAuth2** credential and select it on **Append rows to sheet**. Make a sheet tab (name in the Set node) whose header row is the column list in the Deliver note.\n3. Open **Set search** and change the values: what to search, the Google Sheets target, and `maxChargeUsd`, the most one run may cost.\n4. Run once by hand, check the result, then activate.\n\n### Cost\nAbout $0.026 per run at most on Apify's free plan for 60 results (one keyword); `maxChargeUsd` caps every run.\n\n### Limitations\nNeeds an Apify account (Apify bills the Actor's results to it) and the Apify community node. Runs that fail or hit `maxChargeUsd` stop the workflow at the Apify node; check the run in Apify Console.\n\n### Customization\nAmazon shows ads mostly to home connections, so on the default datacenter proxy some runs see few or no ads; for a fuller report set `proxyConfiguration: { useApifyProxy: true, apifyProxyGroups: ['RESIDENTIAL'] }` in the Apify node's JSON (a paid add-on per page, see the Store page). Add keywords to `searches`, or remove the `p.sponsored === true` check in the Code node to log organic positions too.",
        "height": 860,
        "width": 640
      }
    },
    {
      "id": "7036213d-4dfb-5c88-acad-8452c6a08b57",
      "name": "Run the Actor",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        220,
        140
      ],
      "parameters": {
        "content": "## Run the Actor\nEdit the search and the spend cap in **Set search**. The Apify node waits for the run and returns its results.",
        "height": 340,
        "width": 540,
        "color": 7
      }
    },
    {
      "id": "4c34b033-7218-52de-8c01-b70a8ac85a72",
      "name": "Deliver",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        740,
        140
      ],
      "parameters": {
        "content": "## Deliver\nKeep result rows, shape them and send them to Google Sheets. Nothing is sent when there is nothing new. Header row: scraped_at, search_keyword, position, brand_guess, asin, title, price, rating, reviews_count, product_url.",
        "height": 340,
        "width": 540,
        "color": 7
      }
    },
    {
      "id": "63850a95-a6d3-5bd6-8766-6bcb4b7c3f58",
      "name": "Every Monday at 08:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggersAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      }
    },
    {
      "id": "c2d32ec5-aec6-56aa-a4bc-bbf698b0f993",
      "name": "Set search",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        300
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "93bda65f-aca5-517e-9990-fe4c90155c24",
              "name": "searches",
              "value": "[\"yoga mat\"]",
              "type": "array"
            },
            {
              "id": "fa360f8b-fe70-5c1b-aba6-9d34e8ae2669",
              "name": "marketplace",
              "value": "com",
              "type": "string"
            },
            {
              "id": "7e93042b-0e6b-5a60-9c1e-0c84b8424aaf",
              "name": "maxResultsPerSearch",
              "value": 60,
              "type": "number"
            },
            {
              "id": "abd1c406-c8b9-5e44-b6af-d32058275561",
              "name": "maxChargeUsd",
              "value": 0.1,
              "type": "number"
            },
            {
              "id": "84e8efd1-30c2-5378-a619-42bac5bed9a4",
              "name": "spreadsheetUrl",
              "value": "https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit",
              "type": "string"
            },
            {
              "id": "194c7e3d-936d-540f-b768-38abc87311d3",
              "name": "sheetTab",
              "value": "Sponsored",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "c23e8863-acd0-5455-9061-8b7baab55d45",
      "name": "Run Amazon Search Results Scraper",
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        520,
        300
      ],
      "parameters": {
        "resource": "Actors",
        "operation": "Run actor and get dataset",
        "actorSource": "store",
        "actorId": {
          "__rl": true,
          "mode": "list",
          "value": "ofbi2mI4Ybf92lioa",
          "cachedResultName": "Amazon Search Results Scraper (aurelix/amazon-product-search)",
          "cachedResultUrl": "https://console.apify.com/actors/ofbi2mI4Ybf92lioa/input"
        },
        "actorInputMode": "json",
        "customBody": "={{ JSON.stringify({ searches: $json.searches, marketplace: $json.marketplace, maxResultsPerSearch: $json.maxResultsPerSearch, includeSponsored: true }) }}",
        "memory": 256,
        "timeout": 900,
        "maxTotalChargeUsd": "={{ $json.maxChargeUsd }}"
      }
    },
    {
      "id": "0b9da74a-4a79-58e5-a397-c54b0dc017b8",
      "name": "Shape results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        300
      ],
      "parameters": {
        "jsCode": "const rows = $input.all().map(i => i.json).filter(p => p.asin && p.sponsored === true);\nrows.forEach(p => { p.brand_guess = (p.title || '').split(' ')[0]; });\nreturn rows.map(p => ({ json: { scraped_at: Array.isArray(p.scraped_at) ? p.scraped_at.join(', ') : (p.scraped_at ?? ''), search_keyword: Array.isArray(p.search_keyword) ? p.search_keyword.join(', ') : (p.search_keyword ?? ''), position: Array.isArray(p.position) ? p.position.join(', ') : (p.position ?? ''), brand_guess: Array.isArray(p.brand_guess) ? p.brand_guess.join(', ') : (p.brand_guess ?? ''), asin: Array.isArray(p.asin) ? p.asin.join(', ') : (p.asin ?? ''), title: Array.isArray(p.title) ? p.title.join(', ') : (p.title ?? ''), price: Array.isArray(p.price) ? p.price.join(', ') : (p.price ?? ''), rating: Array.isArray(p.rating) ? p.rating.join(', ') : (p.rating ?? ''), reviews_count: Array.isArray(p.reviews_count) ? p.reviews_count.join(', ') : (p.reviews_count ?? ''), product_url: Array.isArray(p.product_url) ? p.product_url.join(', ') : (p.product_url ?? '') } }));"
      }
    },
    {
      "id": "bc8cc89c-11e3-579b-ae2c-f0d60befe21d",
      "name": "Append rows to sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $('Set search').first().json.spreadsheetUrl }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('Set search').first().json.sheetTab }}"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "scraped_at",
              "displayName": "scraped_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "search_keyword",
              "displayName": "search_keyword",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "position",
              "displayName": "position",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "brand_guess",
              "displayName": "brand_guess",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "asin",
              "displayName": "asin",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "rating",
              "displayName": "rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "reviews_count",
              "displayName": "reviews_count",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "product_url",
              "displayName": "product_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "position": [
        1040,
        300
      ]
    }
  ],
  "connections": {
    "Every Monday at 08:00": {
      "main": [
        [
          {
            "node": "Set search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set search": {
      "main": [
        [
          {
            "node": "Run Amazon Search Results Scraper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Amazon Search Results Scraper": {
      "main": [
        [
          {
            "node": "Shape results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape results": {
      "main": [
        [
          {
            "node": "Append rows to sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
