{ "name": "Save Analytics Sessions by Country to Airtable", "nodes": [ { "name": "On clicking 'execute'", "type": "n8n-nodes-base.manualTrigger", "position": [ 270, 300 ], "parameters": {}, "typeVersion": 1, "id": "analytics-sessions-by-country-to-airtable-0" }, { "name": "Google Analytics", "type": "n8n-nodes-base.googleAnalytics", "position": [ 470, 300 ], "parameters": { "resource": "report", "operation": "get", "propertyType": "ga4", "propertyId": { "__rl": true, "mode": "id", "value": "YOUR_GA4_PROPERTY_ID" }, "dateRange": "custom", "startDate": "2025-01-01", "endDate": "2025-01-31", "metricsGA4": { "metricValues": [ { "listName": "sessions" } ] }, "dimensionsGA4": { "dimensionValues": [ { "listName": "country" } ] }, "returnAll": false, "limit": 10000, "simple": false, "additionalFields": {} }, "typeVersion": 2, "id": "analytics-sessions-by-country-to-airtable-1" }, { "id": "analytics-sessions-by-country-to-airtable-2", "name": "Validate report rows", "type": "n8n-nodes-base.code", "typeVersion": 2, "parameters": { "mode": "runOnceForAllItems", "jsCode": "function rows({report}){\n if(!report||typeof report!=='object')throw Error('Invalid Analytics report');\n const data=report.raw??report;if(!data||typeof data!=='object'||Array.isArray(data))throw Error('Invalid Analytics response');\n const rows=data.rows??[];if(!Array.isArray(rows))throw Error('Invalid Analytics rows');const count=data.rowCount??(rows.length===0?0:null);\n if(!Number.isInteger(count)||count<0||count!==rows.length||count>10000)throw Error('Incomplete Analytics report');\n if(!rows.length)return {rows:[]};\n if(data.dimensionHeaders?.length!==1||data.dimensionHeaders[0]?.name!=='country'||data.metricHeaders?.length!==1||data.metricHeaders[0]?.name!=='sessions')throw Error('Unexpected Analytics columns');\n return {rows:rows.map(row=>{const country=row?.dimensionValues?.[0]?.value,n=row?.metricValues?.[0]?.value;if(typeof country!=='string'||!country||typeof n!=='string'||!/^\\d+$/.test(n)||!Number.isSafeInteger(Number(n)))throw Error('Invalid Analytics row');return {Country:country,Metric:Number(n)};})};\n}\n\nreturn rows({report:$input.first().json}).rows.map(json=>({json}));" } }, { "name": "Airtable", "type": "n8n-nodes-base.airtable", "position": [ 870, 300 ], "parameters": { "authentication": "airtableTokenApi", "application": "YOUR_AIRTABLE_BASE_ID", "table": "Analytics", "operation": "append", "addAllFields": true, "options": {} }, "typeVersion": 1, "id": "analytics-sessions-by-country-to-airtable-3" } ], "active": false, "settings": {}, "connections": { "On clicking 'execute'": { "main": [ [ { "node": "Google Analytics", "type": "main", "index": 0 } ] ] }, "Google Analytics": { "main": [ [ { "node": "Validate report rows", "type": "main", "index": 0 } ] ] }, "Validate report rows": { "main": [ [ { "node": "Airtable", "type": "main", "index": 0 } ] ] } }, "pinData": {} }