{"id":23841991,"url":"https://github.com/ajaxbarcelonacruyff/ga4_create_custom_dimensions","last_synced_at":"2026-06-23T11:31:07.260Z","repository":{"id":266170399,"uuid":"897602859","full_name":"ajaxbarcelonacruyff/ga4_create_custom_dimensions","owner":"ajaxbarcelonacruyff","description":"Batch creation of custom dimensions for multiple GA4 properties.","archived":false,"fork":false,"pushed_at":"2024-12-23T07:24:12.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T05:25:53.632Z","etag":null,"topics":["ga4","gas","googleanalytics"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajaxbarcelonacruyff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-02T23:05:14.000Z","updated_at":"2025-01-31T01:48:18.000Z","dependencies_parsed_at":"2025-01-02T18:34:27.390Z","dependency_job_id":"114299d5-2fb1-4c29-9650-bde5df22738c","html_url":"https://github.com/ajaxbarcelonacruyff/ga4_create_custom_dimensions","commit_stats":null,"previous_names":["ajaxbarcelonacruyff/ga4_create_custom_dimensions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajaxbarcelonacruyff/ga4_create_custom_dimensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxbarcelonacruyff%2Fga4_create_custom_dimensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxbarcelonacruyff%2Fga4_create_custom_dimensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxbarcelonacruyff%2Fga4_create_custom_dimensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxbarcelonacruyff%2Fga4_create_custom_dimensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajaxbarcelonacruyff","download_url":"https://codeload.github.com/ajaxbarcelonacruyff/ga4_create_custom_dimensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaxbarcelonacruyff%2Fga4_create_custom_dimensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34686727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ga4","gas","googleanalytics"],"created_at":"2025-01-02T18:34:08.214Z","updated_at":"2026-06-23T11:31:07.241Z","avatar_url":"https://github.com/ajaxbarcelonacruyff.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!Note]\n\u003e This article contains information as of July 2022. Please refer to the official website for the latest updates.\n\n# Bulk Creating Custom Dimensions Across Multiple GA4 Properties\n\nIn the [previous article](https://github.com/ajaxbarcelonacruyff/ga4_create_multi_properties), we discussed how to bulk create GA4 properties. This time, we will extend that process to create custom dimensions for each property in bulk.\n\n## Steps\n\n1. Create a list of custom dimensions.\n2. Read the list of target GA4 properties (skipped in this guide).\n3. Read the custom dimensions list and create them in bulk.\n\n# Creating a List of Custom Dimensions\n\nPrepare a list of custom dimensions in Google Sheets.\n\n- **Sheet Name:** customdimensions\n- **Column A:** Custom dimension name\n- **Column B:** Scope (EVENT, USER)\n\n![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3939399/fa5083a1-39b8-962b-e5e7-de96a40af336.png)\n\n# Writing the Google Apps Script\n\nWe will again use the Google Analytics Admin API. For instructions on setting it up, refer to [the previous article](https://github.com/ajaxbarcelonacruyff/ga4_create_multi_properties).\n\n## Reading the List of Target GA4 Properties\n\nThis step involves reading a list of GA4 properties from Google Sheets. For simplicity, this part is skipped here, and the property IDs are directly added to an array in the script.\n\n## Reading the List of Custom Dimensions\n\nCreate a function `getCustomDimensionsFromSheet()` to read the list of custom dimensions from the Google Sheets file.\n\nThis function returns an array of objects with the following attributes:\n\n```javascript\nconst FILEKEY = \"abcdefghijklmno\"; // Google Sheet key from the URL\n\nfunction getCustomDimensionsFromSheet() {\n  const sheetName = \"customdimensions\";\n  const spreadsheet = SpreadsheetApp.openById(FILEKEY);\n  const sheet = spreadsheet.getSheetByName(sheetName);\n  const lastRow = sheet.getLastRow(); \n  const data = sheet.getRange(2, 1, lastRow, 2).getValues();\n  const result = [];\n  for (let i = 0; i \u003c data.length; i++) {\n    if (!data[i][0]) break;\n    result.push({\n      \"displayName\": data[i][0],\n      \"parameterName\": data[i][0],\n      \"scope\": data[i][1] // e.g., \"EVENT\"\n    });\n  }\n  return result;\n}\n```\n\nExample output:\n\n- `displayName`: \"customer_status\"\n- `parameterName`: \"customer_status\"\n- `scope`: \"USER\"\n\n## Creating Custom Dimensions in GA4 Properties\n\nUsing the above information, create a function `createCustomDimension()` that adds a custom dimension to a specific GA4 property.\n\n```javascript\nfunction createCustomDimension(propertyId, customDimensionData) {\n/*\npropertyId = 3234568;\ncustomDimensionData = {\n  \"displayName\": \"customer_status\",\n  \"parameterName\": \"customer_status\",\n  \"scope\": \"USER\" //\"EVENT\"\n};\n*/\n  return AnalyticsAdmin.Properties.CustomDimensions.create(customDimensionData, `properties/${propertyId}`);\n}\n```\n\n## Looping Through Properties and Dimensions\n\nFinally, create a `main()` function that iterates through all GA4 properties and creates custom dimensions for each.\n\n```javascript\nfunction main() {\n  const properties = [\n    3234568,\n    3234555,\n    3234542,\n    3234609,\n    3234553,\n    3234563,\n    3234584\n  ]; // For simplicity, the script to load property IDs is skipped and IDs are added directly\n\n  for (const property of properties) {\n    const customDimensions = getCustomDimensionsFromSheet();\n    for (const cd of customDimensions) {\n      try {\n        console.log(createCustomDimension(property, cd));\n      } catch (e) {\n        console.log(e);\n      }\n    }\n  }\n}\n```\n\nExecuting the above functions will create custom dimensions for each GA4 property.\n\n![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3939399/4f81a0ed-77ad-4e41-3565-918b41f7530a.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaxbarcelonacruyff%2Fga4_create_custom_dimensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajaxbarcelonacruyff%2Fga4_create_custom_dimensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaxbarcelonacruyff%2Fga4_create_custom_dimensions/lists"}