{
  "id": "hfswzlNeZ8jIRCWk",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Get new Featured Snippet keyword wins for your domain via email with DataForSEO",
  "tags": [],
  "nodes": [
    {
      "id": "a377bf22-f81d-4f89-8777-556a60ceaa6f",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        448,
        64
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "eae65a1a-1537-4b26-ac41-14eff13e72d7",
      "name": "Get ranked keywords",
      "type": "n8n-nodes-dataforseo.dataForSeoLabsApi",
      "position": [
        656,
        432
      ],
      "parameters": {
        "limit": 1000,
        "offset": "={{ $runIndex * 1000 }}",
        "operation": "get-ranked-keywords",
        "item_types": [
          "featured_snippet"
        ],
        "target_any": "={{ $('Get targets').item.json.Domain }}",
        "language_name": "={{ $('Get targets').item.json.Language }}",
        "location_name": "={{ $('Get targets').item.json.Location }}"
      },
      "credentials": {
        "dataForSeoApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "08d66742-7ae7-48a2-9792-f31efc45054b",
      "name": "Get previous keywords",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        224,
        64
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1392477424,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit#gid=1392477424",
          "cachedResultName": "Keywords"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit?usp=drivesdk",
          "cachedResultName": "New Ranked Keywords for featured_snippet from Google with DataForSEO"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7,
      "alwaysOutputData": true
    },
    {
      "id": "c6d988eb-d03a-4c66-8c0e-968b674651a6",
      "name": "Get targets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        944,
        64
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit#gid=0",
          "cachedResultName": "Targets"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit?usp=drivesdk",
          "cachedResultName": "New Ranked Keywords for featured_snippet from Google with DataForSEO"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b092f14f-7206-43bd-97c8-c02e9a562b04",
      "name": "Find new keywords",
      "type": "n8n-nodes-base.code",
      "position": [
        816,
        928
      ],
      "parameters": {
        "jsCode": "let oldKeywords = new Set([]);\nif ($('Aggregate').first().json.data) {\n oldKeywords = new Set($('Aggregate').first().json.data\n  .filter(item => item.Target == $('Get targets').first().json.Domain)\n  .map(item => item.Keyword));\n}\n\nlet newKeywords = [];\nif ($('Merge \"items\" with last response').first().json.items) {\n newKeywords = $('Merge \"items\" with last response').first().json.items\n  .map(item => item.keyword_data.keyword);\n}\n\nlet diff;\nif (oldKeywords.size > 0) {\n  diff = newKeywords.filter(x => !oldKeywords.has(x));\n} else {\n  diff = [];\n}\n\nreturn [\n  {\n    json: {\n      diff\n    }\n  }\n];"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "a4f52fc6-39ca-4a1a-af99-199fac245cee",
      "name": "Append keyword in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        368,
        928
      ],
      "parameters": {
        "columns": {
          "value": {
            "Url": "={{ $json.ranked_serp_element.serp_item.url }}",
            "Date": "={{ new Date().toLocaleDateString('en-CA') }}",
            "Rank": "={{ $json.ranked_serp_element.serp_item.rank_group }}",
            "Target": "={{ $('Get targets').item.json.Domain }}",
            "Keyword": "={{ $json.keyword_data.keyword }}",
            "Search Volume": "={{ $json.keyword_data.keyword_info.search_volume }}",
            "SERP Item Types": "={{ $json.ranked_serp_element.serp_item_types.join(', ') }}"
          },
          "schema": [
            {
              "id": "Target",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Target",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Keyword",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Keyword",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Rank",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Rank",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Search Volume",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Search Volume",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Url",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "SERP Item Types",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "SERP Item Types",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1392477424,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit#gid=1392477424",
          "cachedResultName": "Keywords"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit?usp=drivesdk",
          "cachedResultName": "New Ranked Keywords for featured_snippet from Google with DataForSEO"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "368770b6-2730-4146-af9e-8717b12c1051",
      "name": "Run every Monday",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        64
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "76166745-46f2-447d-bf74-d0d215f0aafb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -80
      ],
      "parameters": {
        "color": 6,
        "width": 640,
        "height": 304,
        "content": "## Get previous keywords and clear the sheet\nCreate a Google Sheets connection and select the spreadsheet where keywords should be saved. The sheet must have the same columns as in [this Example](https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit?gid=1392477424#gid=1392477424)."
      },
      "typeVersion": 1
    },
    {
      "id": "dbb53a0a-b97f-4a8a-969e-0bcda8a42dc7",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -80
      ],
      "parameters": {
        "color": 6,
        "height": 304,
        "content": "## Get targets\nSelect a spreadsheet with your target domains. The spreadsheet must have the same columns as in [this Example](https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit?gid=0#gid=0)."
      },
      "typeVersion": 1
    },
    {
      "id": "9e59f873-b380-42b5-9570-6ef7a1c69f7c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        336
      ],
      "parameters": {
        "color": 6,
        "width": 1344,
        "height": 352,
        "content": "## Get newly earned Featured Snippet keywords with DataForSEO\nCreate a DataForSEO connection and set up additional parameters if needed."
      },
      "typeVersion": 1
    },
    {
      "id": "f7b96365-6522-49c8-9047-46467558d24d",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        800
      ],
      "parameters": {
        "color": 6,
        "width": 1248,
        "height": 288,
        "content": "## Save new Featured Snippet keywords to a spreadsheet and send an email\nSelect the same spreadsheet with your keywords as in the first Google Sheets node.\nCreate a Gmail connection and set a receiver. Add additional information to the message if needed."
      },
      "typeVersion": 1
    },
    {
      "id": "5e0e9b49-7fa5-479b-9518-8b5e18d5f1b9",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        80
      ],
      "parameters": {
        "width": 400,
        "height": 592,
        "content": "This workflow uses DataForSEO Labs API to identify new search queries where your domain started appearing in Google\u2019s Featured Snippet results. Newly detected keywords are saved to Google Sheets, and a brief email summary is sent to you so you can quickly review recent wins.\n\n## How it works\n1. Runs on a predefined schedule (default: once a week).\n2. Reads your keywords and domains from Google Sheets.\n3. Extracts the latest data on Google\u2019s Featured Snippet results via DataForSEO API.\n4. Compares the data with the previous snapshot.\n5. Logs newly ranked keywords in Featured Snippets to Google Sheets.\n6. Sends a summary email with key highlights.\n\n## Setup steps\n1. Indicate your spreadsheets with keywords and target domains.\n2. Create or select your DataForSEO connection (use [your API login and password](https://app.dataforseo.com/api-access)).\n3. Connect your Gmail to receive a summary of new Featured Snippet wins.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e7fd883a-de58-49dc-acd3-c83386fcb1b3",
      "name": "Aggregate1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        592,
        928
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "a5f97ca2-5029-41e7-a648-397715b22f98",
      "name": "Clear sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        672,
        64
      ],
      "parameters": {
        "operation": "clear",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1392477424,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit#gid=1392477424",
          "cachedResultName": "Keywords"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1pRNkz1us8N_w_Sw-8axiMxUDu7to2tIVFXyY5W7gH3U/edit?usp=drivesdk",
          "cachedResultName": "New Ranked Keywords for featured_snippet from Google with DataForSEO"
        },
        "keepFirstRow": true
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "9ffd9efa-bdda-4f0f-94c3-7d2d6a4a94ad",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1248,
        928
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=<html> <body> <p>New keywords for which your target {{ $('Get targets').item.json.Domain }} ranks in featured snippet: {{ $json.diff.join(', ') }}</p> </body> </html>",
        "options": {},
        "subject": "New Featured Snippet Keywords for Your Domain"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3f9a2b35-9618-4ef6-9b43-4a5f2f70e4c2",
      "name": "Initialize \"items\" field",
      "type": "n8n-nodes-base.set",
      "position": [
        208,
        512
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0126c659-03a5-4fc8-bd76-62d2ecea1195",
              "name": "items",
              "type": "array",
              "value": "={{ [] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "32401749-a524-4e11-9717-e56cdd0e1d30",
      "name": "Set \"items\" field",
      "type": "n8n-nodes-base.set",
      "position": [
        432,
        512
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4b3c95a2-4e38-4e37-8e2f-a7e4544808d6",
              "name": "items",
              "type": "array",
              "value": "={{ $json.items }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9fb8d76c-42a0-4e01-9ee5-249dbbaa0de4",
      "name": "Merge \"items\" with DFS response",
      "type": "n8n-nodes-base.set",
      "position": [
        880,
        416
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ddd82419-e43e-44d8-919c-2d6602704da5",
              "name": "items",
              "type": "array",
              "value": "={{ [ ...$('Set \"items\" field').item.json.items, ...$json.tasks[0].result[0].items] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4feead53-4587-47be-a42c-02b06e1017d1",
      "name": "Has more pages?",
      "type": "n8n-nodes-base.if",
      "position": [
        1104,
        496
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cd5943f7-df0b-4329-8436-9a1af3ec7caf",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $runIndex }}",
              "rightValue": "={{ $('Get ranked keywords').item.json.tasks[0].result[0].total_count / 1000 - 1}}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b967123e-85d6-4cd3-8eb7-e2a16f20ccc3",
      "name": "Merge \"items\" with last response",
      "type": "n8n-nodes-base.set",
      "position": [
        1360,
        512
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1e2c8353-5628-4948-abe6-35f8d0f660a5",
              "name": "items",
              "type": "array",
              "value": "={{ [...$('Set \"items\" field').item.json.items, ... $('Get ranked keywords').item.json.tasks[0].result[0].items]}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "53ca57d5-da75-4772-a5c4-1fa9362b0eb9",
      "name": "Filter (has new keywords)",
      "type": "n8n-nodes-base.filter",
      "position": [
        1024,
        928
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a3db3215-80c8-45bd-95ff-39ca37c26fe1",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.diff }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "8189b3ff-b615-4922-8085-5ecdc9ef9098",
      "name": "Split out (items)",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        144,
        928
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "items"
      },
      "typeVersion": 1
    },
    {
      "id": "9bd825da-1d53-4d96-b181-f893ed5096a2",
      "name": "Loop over targets",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -16,
        496
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "fe1e5eec-e045-4cea-a139-d34037ba8b9c",
  "connections": {
    "Aggregate": {
      "main": [
        [
          {
            "node": "Clear sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Find new keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clear sheet": {
      "main": [
        [
          {
            "node": "Get targets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get targets": {
      "main": [
        [
          {
            "node": "Loop over targets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Loop over targets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has more pages?": {
      "main": [
        [
          {
            "node": "Set \"items\" field",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge \"items\" with last response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run every Monday": {
      "main": [
        [
          {
            "node": "Get previous keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find new keywords": {
      "main": [
        [
          {
            "node": "Filter (has new keywords)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop over targets": {
      "main": [
        [],
        [
          {
            "node": "Initialize \"items\" field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set \"items\" field": {
      "main": [
        [
          {
            "node": "Get ranked keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split out (items)": {
      "main": [
        [
          {
            "node": "Append keyword in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get ranked keywords": {
      "main": [
        [
          {
            "node": "Merge \"items\" with DFS response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get previous keywords": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append keyword in sheet": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Initialize \"items\" field": {
      "main": [
        [
          {
            "node": "Set \"items\" field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter (has new keywords)": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge \"items\" with DFS response": {
      "main": [
        [
          {
            "node": "Has more pages?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge \"items\" with last response": {
      "main": [
        [
          {
            "node": "Split out (items)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}