ID
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
대부분의 Google Ads 항목은 식별자를 반환하는 getId()
메서드를 노출합니다. 대부분의 경우 ID가 반드시 필요한 것은 아니지만 다음과 같은 경우에 유용할 수 있습니다.
- 보고서 작업
- ID는 보고서 행을 실제 Google Ads 항목에 연결하는 좋은 방법입니다.
- 외부 데이터 스토어와의 매핑 유지
- 자체 데이터베이스에 ID 기반 정보가 이미 저장되어 있을 수 있습니다.
- 성능 향상을 꾀하는 경우
ID로 가져오는 것이 대안보다 빠른 경우가 많습니다. 단일 항목을 가져오는 코드도 약간 더 쉽습니다.
let campaigns = AdsApp.campaigns()
.withIds([678678])
.get();
// versus
let campaigns = AdsApp.campaigns()
.withCondition("Name='My Campaign'")
.get();
고유성
캠페인 ID와 광고 그룹 ID는 고유합니다. 두 캠페인 또는 광고 그룹이 동일한 ID를 공유할 수 없습니다. 하지만 광고와 키워드는 복합 ID를 갖습니다. 키워드의 고유 식별자는 광고 그룹 ID와 키워드 ID의 조합입니다.
마찬가지로 광고의 고유 식별자는 광고 그룹 ID와 광고 ID의 조합입니다. 이는 selector.withIds()
가 호출되는 방식에 영향을 미칩니다.
캠페인 및 광고 그룹의 경우 selector.withIds()
은 숫자 배열을 예상합니다.
let ids = [123123, 234234, 345345];
let campaignSelector = AdsApp.campaigns().withIds(ids);
하지만 광고와 키워드의 경우 selector.withIds()
에 2요소 배열의 배열이 필요하며 첫 번째 요소는 광고 그룹 ID입니다. 다음 스니펫은 광고 그룹에서 키워드 3개를 가져옵니다.
let adGroupId = 123123;
let keywordSelector = AdsApp.keywords().withIds([
[adGroupId, 234234],
[adGroupId, 345345],
[adGroupId, 456456]
]);
광고를 가져올 때도 동일한 구조가 적용됩니다.
임시 ID
여러 작업이 포함된 변이 요청을 사용할 때는 API 응답을 받을 때까지 전체 리소스 이름을 사용할 수 없으므로 리소스를 서로 연결하기 위해 임시 ID를 사용해야 하는 경우가 있습니다. 임시 ID는 -1로 시작하는 음수여야 하며 동일한 변이 요청 내에서 반복될 수 없습니다. 임시 ID를 효과적으로 사용하려면 중복된 임시 ID가 생성되지 않도록 코드를 작성해야 합니다.
let nextId = -1;
function getNextTempId() {
const ret = nextId;
nextId -= 1;
return ret;
}
getNextTempId
에 대한 각 연속 호출은 이전 호출보다 1이 적은 숫자를 반환합니다. 모든 임시 ID는 음수여야 하므로 -1부터 시작합니다.
임시 ID는 작업 또는 변이 요청 간에 기억되지 않습니다. 이전 변이 요청에서 생성된 리소스를 참조하려면 실제 리소스 이름을 사용합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-10(UTC)
[null,null,["최종 업데이트: 2025-09-10(UTC)"],[[["\u003cp\u003eMost Google Ads entities have a \u003ccode\u003egetId()\u003c/code\u003e method, which returns a unique identifier that can be useful for linking data, improving performance, and referencing external databases.\u003c/p\u003e\n"],["\u003cp\u003eWhen working with reports, IDs can connect report rows to specific Google Ads entities.\u003c/p\u003e\n"],["\u003cp\u003eFetching entities by ID is often faster than using other methods like filtering by name.\u003c/p\u003e\n"],["\u003cp\u003eCampaign and ad group IDs are unique, while ad and keyword IDs are composite, requiring both the ad group ID and their individual ID for unique identification.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eselector.withIds()\u003c/code\u003e method is used to fetch entities by ID, taking an array of numbers for campaigns and ad groups and an array of two-element arrays (ad group ID and entity ID) for ads and keywords.\u003c/p\u003e\n"]]],[],null,["Most Google Ads entities expose a `getId()` method that returns their\nidentifier. While not strictly necessary in most cases, IDs may come in handy\nwhen\n\nWorking with [reports](/google-ads/scripts/docs/features/reports)\n: IDs provide a good way to link a report row to the actual Google Ads entity.\n\nMaintaining a mapping with an external datastore\n: You may already have ID-based information stored in your own database.\n\nLooking for a bit of a performance boost\n\n: Fetching by IDs is often quicker than alternatives. The code for fetching a\n single entity is a bit easier too:\n\n let campaigns = AdsApp.campaigns()\n .withIds([678678])\n .get();\n // versus\n let campaigns = AdsApp.campaigns()\n .withCondition(\"Name='My Campaign'\")\n .get();\n\nUniqueness\n\nCampaign IDs and ad group IDs are unique: no two campaigns or ad groups will\never share the same ID. Ads and keywords, however, have composite IDs: a unique\nidentifier of a keyword is a combination of its ad group ID and keyword ID.\nLikewise, a unique identifier of an ad is a combination of its ad group ID and\nad ID. This has implications for the way `selector.withIds()` is called.\n\nFor campaigns and ad groups, `selector.withIds()` expects an array of numbers: \n\n let ids = [123123, 234234, 345345];\n let campaignSelector = AdsApp.campaigns().withIds(ids);\n\nFor ads and keywords, however, `selector.withIds()` needs an array of\ntwo-element arrays, the first element being the ad group ID. The following\nsnippet retrieves three keywords from an ad group: \n\n let adGroupId = 123123;\n let keywordSelector = AdsApp.keywords().withIds([\n [adGroupId, 234234],\n [adGroupId, 345345],\n [adGroupId, 456456]\n ]);\n\nThe same construct applies when fetching ads.\n\nTemporary IDs\n\nWhen working with a [mutate request](/google-ads/scripts/docs/features/mutate)\nwith multiple operations, you'll occasionally need to use\n[temporary IDs](/google-ads/api/docs/batch-processing/temporary-ids) to link\nresources to each other, since the full resource names won't be available until\nyou get the API response. Temporary IDs must be negative numbers starting with\n-1, and cannot repeat within the same mutate request. In order to use temporary\nIDs effectively, you'll have to write some code to ensure that you don't create\nduplicate temporary IDs: \n\n let nextId = -1;\n\n function getNextTempId() {\n const ret = nextId;\n nextId -= 1;\n return ret;\n }\n\nEach successive call to `getNextTempId` will return a number one less than the\nprevious. Since all temp IDs must be negative, start at -1.\n\nTemporary IDs are not remembered across jobs or mutate requests. To reference a\nresource created in a previous mutate request, use its actual resource name."]]