@pipedream/google_ads 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +4 -4
  2. package/actions/add-contact-to-list-by-email/add-contact-to-list-by-email.mjs +1 -1
  3. package/actions/common/bidding.mjs +196 -0
  4. package/actions/common/conversion-upload.mjs +131 -0
  5. package/actions/common/props.mjs +1 -1
  6. package/actions/create-ad-group-report/create-ad-group-report.mjs +2 -2
  7. package/actions/create-ad-report/create-ad-report.mjs +2 -2
  8. package/actions/create-campaign-report/create-campaign-report.mjs +2 -2
  9. package/actions/create-customer-list/common-constants.mjs +10 -10
  10. package/actions/create-customer-list/create-customer-list.mjs +3 -3
  11. package/actions/create-customer-report/create-customer-report.mjs +2 -2
  12. package/actions/create-or-remove-campaign-criteria/create-or-remove-campaign-criteria.mjs +214 -0
  13. package/actions/create-or-remove-campaign-shared-set/create-or-remove-campaign-shared-set.mjs +155 -0
  14. package/actions/create-or-remove-shared-criteria/create-or-remove-shared-criteria.mjs +180 -0
  15. package/actions/create-or-update-ad-group/create-or-update-ad-group.mjs +315 -0
  16. package/actions/create-or-update-ad-group-ad/create-or-update-ad-group-ad.mjs +203 -0
  17. package/actions/create-or-update-bidding-strategy/create-or-update-bidding-strategy.mjs +185 -0
  18. package/actions/create-or-update-campaign/create-or-update-campaign.mjs +300 -0
  19. package/actions/create-or-update-campaign-budget/create-or-update-campaign-budget.mjs +212 -0
  20. package/actions/create-or-update-keywords/create-or-update-keywords.mjs +275 -0
  21. package/actions/create-or-update-shared-sets/create-or-update-shared-sets.mjs +180 -0
  22. package/actions/create-report/create-report.mjs +5 -7
  23. package/actions/create-responsive-search-ad/create-responsive-search-ad.mjs +202 -0
  24. package/actions/generate-keyword-ideas/generate-keyword-ideas.mjs +3 -3
  25. package/actions/get-keyword-quality-scores/get-keyword-quality-scores.mjs +107 -0
  26. package/actions/list-account-id-options/list-account-id-options.mjs +1 -1
  27. package/actions/list-ad-group-ads/list-ad-group-ads.mjs +55 -0
  28. package/actions/list-ad-group-criteria/list-ad-group-criteria.mjs +55 -0
  29. package/actions/list-ad-groups/list-ad-groups.mjs +55 -0
  30. package/actions/list-bidding-strategies/list-bidding-strategies.mjs +55 -0
  31. package/actions/list-campaign-budgets/list-campaign-budgets.mjs +55 -0
  32. package/actions/list-campaign-criteria/list-campaign-criteria.mjs +55 -0
  33. package/actions/list-campaign-shared-sets/list-campaign-shared-sets.mjs +55 -0
  34. package/actions/list-campaigns/list-campaigns.mjs +55 -0
  35. package/actions/list-customer-clients/list-customer-clients.mjs +2 -2
  36. package/actions/list-keywords/list-keywords.mjs +55 -0
  37. package/actions/list-shared-criteria/list-shared-criteria.mjs +55 -0
  38. package/actions/list-shared-sets/list-shared-sets.mjs +55 -0
  39. package/actions/send-offline-conversion/send-offline-conversion.mjs +4 -4
  40. package/actions/update-campaign-ai-max-settings/update-campaign-ai-max-settings.mjs +167 -0
  41. package/actions/upload-call-conversion/upload-call-conversion.mjs +65 -0
  42. package/actions/upload-click-conversion/upload-click-conversion.mjs +121 -0
  43. package/common/common-report.mjs +5 -7
  44. package/common/constants.mjs +369 -0
  45. package/common/queries.mjs +4 -2
  46. package/common/resources/ad.mjs +25 -70
  47. package/common/resources/adGroup.mjs +2 -3
  48. package/common/resources/campaign.mjs +7 -10
  49. package/common/resources/customer.mjs +3 -4
  50. package/common/utils.mjs +4 -0
  51. package/google_ads.app.mjs +657 -19
  52. package/package.json +1 -1
  53. package/sources/new-campaign-created/new-campaign-created.mjs +3 -3
  54. package/sources/new-lead-form-entry/new-lead-form-entry.mjs +3 -3
@@ -1,7 +1,11 @@
1
1
  import { axios } from "@pipedream/platform";
2
- import { CORE_DATE_SEGMENTS } from "./common/constants.mjs";
2
+ import {
3
+ API_VERSION, CORE_DATE_SEGMENTS,
4
+ } from "./common/constants.mjs";
3
5
  import { QUERIES } from "./common/queries.mjs";
4
- import { getResourceOption } from "./common/utils.mjs";
6
+ import {
7
+ getResourceOption, sanitizeGaqlString,
8
+ } from "./common/utils.mjs";
5
9
 
6
10
  export default {
7
11
  type: "app",
@@ -30,25 +34,25 @@ export default {
30
34
  }) => ({
31
35
  label: name,
32
36
  value: id,
33
- }));
37
+ })) ?? [];
34
38
  },
35
39
  },
36
40
  accountId: {
37
41
  type: "string",
38
42
  label: "Use Google Ads As",
39
- description: "The ID of an account of a [customer directly accessible by the authenticated user](https://developers.google.com/google-ads/api/reference/rpc/v21/CustomerService/ListAccessibleCustomers?transport=rest). This is usually a Manager Account, used as `login-customer-id` (e.g., `1234567890`). Use the **List Account ID Options** action to get the list of accessible accounts.",
43
+ description: "The ID of an account of a [customer directly accessible by the authenticated user](https://developers.google.com/google-ads/api/reference/rpc/v25/CustomerService/ListAccessibleCustomers?transport=rest). This is usually a Manager Account, used as `login-customer-id` (e.g., `1234567890`). Use the **List Account ID Options** action to get the list of accessible accounts.",
40
44
  async options() {
41
45
  const response = await this.listAccessibleCustomers();
42
46
  return response?.map(((resourceName) => ({
43
47
  label: resourceName,
44
48
  value: resourceName.split("/").pop(),
45
- })));
49
+ }))) ?? [];
46
50
  },
47
51
  },
48
52
  customerClientId: {
49
53
  type: "string",
50
54
  label: "Managed Account",
51
- description: "The ID of a [customer client](https://developers.google.com/google-ads/api/reference/rpc/v21/CustomerClient) from the list of [customers linked to the selected account](https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy) (e.g., `1234567890`). Use the **List Customer Clients** action to get the list of customer clients.",
55
+ description: "The ID of a [customer client](https://developers.google.com/google-ads/api/reference/rpc/v25/CustomerClient) from the list of [customers linked to the selected account](https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy) (e.g., `1234567890`). Use the **List Customer Clients** action to get the list of customer clients.",
52
56
  useQuery: true,
53
57
  optional: true,
54
58
  async options({
@@ -67,7 +71,7 @@ export default {
67
71
  ? "[Manager] "
68
72
  : ""}${descriptiveName}`,
69
73
  value: id,
70
- })).filter(({ value }) => value !== accountId);
74
+ }))?.filter(({ value }) => value !== accountId) ?? [];
71
75
  },
72
76
  },
73
77
  reportResourceFilter: {
@@ -89,7 +93,7 @@ export default {
89
93
  query,
90
94
  pageToken,
91
95
  });
92
- const options = results?.map?.((item) => this.getResourceOption(item, resource));
96
+ const options = results?.map?.((item) => this.getResourceOption(item, resource)) ?? [];
93
97
  return {
94
98
  options,
95
99
  context: {
@@ -124,10 +128,351 @@ export default {
124
128
  .filter((v) => dateRange || !CORE_DATE_SEGMENTS.includes(v));
125
129
  },
126
130
  },
131
+ campaignId: {
132
+ type: "string",
133
+ label: "Campaign",
134
+ description: "Numeric campaign ID (e.g., `1234567890`). Use the **List Campaigns** action to discover valid IDs.",
135
+ useQuery: true,
136
+ async options({
137
+ accountId, customerClientId, query, prevContext,
138
+ }) {
139
+ const pageToken = prevContext?.nextPageToken;
140
+ const {
141
+ results, nextPageToken,
142
+ } = await this.listResources({
143
+ accountId,
144
+ customerClientId,
145
+ resource: "campaign",
146
+ query,
147
+ pageToken,
148
+ });
149
+ const options = results?.map?.((item) => this.getResourceOption(item, "campaign")) ?? [];
150
+ return {
151
+ options,
152
+ context: {
153
+ nextPageToken,
154
+ },
155
+ };
156
+ },
157
+ },
158
+ campaignSharedSetId: {
159
+ type: "string",
160
+ label: "Campaign Shared Set",
161
+ description: "Campaign shared set resource name (e.g., `customers/123/campaignSharedSets/456~789`). Use the **List Campaign Shared Sets** action to discover valid values.",
162
+ useQuery: true,
163
+ async options({
164
+ accountId, customerClientId, query, prevContext,
165
+ }) {
166
+ const pageToken = prevContext?.nextPageToken;
167
+ const {
168
+ results, nextPageToken,
169
+ } = await this.listCampaignSharedSets({
170
+ accountId,
171
+ customerClientId,
172
+ query,
173
+ pageToken,
174
+ });
175
+ const options = results?.map?.((item) => ({
176
+ label: `${item.campaign?.name} → ${item.sharedSet?.name}`,
177
+ value: item.campaignSharedSet?.resourceName,
178
+ })) ?? [];
179
+ return {
180
+ options,
181
+ context: {
182
+ nextPageToken,
183
+ },
184
+ };
185
+ },
186
+ },
187
+ sharedCriterionId: {
188
+ type: "string",
189
+ label: "Shared Criterion",
190
+ description: "Shared criterion resource name (e.g., `customers/123/sharedCriteria/456~789`). Use the **List Shared Criteria** action to discover valid values.",
191
+ useQuery: true,
192
+ async options({
193
+ accountId, customerClientId, query, prevContext,
194
+ }) {
195
+ const pageToken = prevContext?.nextPageToken;
196
+ const {
197
+ results, nextPageToken,
198
+ } = await this.listSharedCriteria({
199
+ accountId,
200
+ customerClientId,
201
+ query,
202
+ pageToken,
203
+ });
204
+ const options = results?.map?.((item) => {
205
+ const criterion = item.sharedCriterion;
206
+ const sharedSetName = item.sharedSet?.name;
207
+ let criterionLabel;
208
+ if (criterion?.type === "KEYWORD") {
209
+ criterionLabel = `[${criterion.keyword?.matchType}] ${criterion.keyword?.text}`;
210
+ } else {
211
+ criterionLabel = `[${criterion?.type}] ${criterion?.criterionId}`;
212
+ }
213
+ return {
214
+ label: `${criterionLabel} (${sharedSetName})`,
215
+ value: criterion?.resourceName,
216
+ };
217
+ }) ?? [];
218
+ return {
219
+ options,
220
+ context: {
221
+ nextPageToken,
222
+ },
223
+ };
224
+ },
225
+ },
226
+ sharedSetId: {
227
+ type: "string",
228
+ label: "Shared Set",
229
+ description: "Numeric shared set ID (e.g., `1234567890`). Use the **List Shared Sets** action to discover valid IDs.",
230
+ useQuery: true,
231
+ async options({
232
+ accountId, customerClientId, query, prevContext,
233
+ }) {
234
+ const pageToken = prevContext?.nextPageToken;
235
+ const {
236
+ results, nextPageToken,
237
+ } = await this.listAllSharedSets({
238
+ accountId,
239
+ customerClientId,
240
+ query,
241
+ pageToken,
242
+ });
243
+ const options = results?.map?.((item) => ({
244
+ label: `[${item.sharedSet?.type}] ${item.sharedSet?.name}`,
245
+ value: item.sharedSet?.id,
246
+ })) ?? [];
247
+ return {
248
+ options,
249
+ context: {
250
+ nextPageToken,
251
+ },
252
+ };
253
+ },
254
+ },
255
+ adGroupCriterionId: {
256
+ type: "string",
257
+ label: "Keyword",
258
+ description: "Keyword criterion resource name (e.g., `customers/123/adGroupCriteria/456~789`). Use the **List Keywords** action to discover valid values.",
259
+ useQuery: true,
260
+ async options({
261
+ accountId, customerClientId, query, prevContext,
262
+ }) {
263
+ const pageToken = prevContext?.nextPageToken;
264
+ const {
265
+ results, nextPageToken,
266
+ } = await this.listKeywords({
267
+ accountId,
268
+ customerClientId,
269
+ query,
270
+ pageToken,
271
+ });
272
+ const options = results?.map?.((item) => ({
273
+ label: `[${item.adGroupCriterion?.keyword?.matchType}] ${item.adGroupCriterion?.keyword?.text}`,
274
+ value: item.adGroupCriterion?.resourceName,
275
+ })) ?? [];
276
+ return {
277
+ options,
278
+ context: {
279
+ nextPageToken,
280
+ },
281
+ };
282
+ },
283
+ },
284
+ adGroupAdId: {
285
+ type: "string",
286
+ label: "Ad Group Ad",
287
+ description: "Ad group ad resource name (e.g., `customers/123/adGroupAds/456~789`). Use the **List Ad Group Ads** action to discover valid values.",
288
+ useQuery: true,
289
+ async options({
290
+ accountId, customerClientId, query, prevContext,
291
+ }) {
292
+ const pageToken = prevContext?.nextPageToken;
293
+ const {
294
+ results, nextPageToken,
295
+ } = await this.listResources({
296
+ accountId,
297
+ customerClientId,
298
+ resource: "ad_group_ad",
299
+ query,
300
+ pageToken,
301
+ });
302
+ const options = results?.map?.((item) => ({
303
+ label: item.adGroupAd?.ad?.name ?? `Ad ${item.adGroupAd?.ad?.id}`,
304
+ value: item.adGroupAd?.resourceName,
305
+ })) ?? [];
306
+ return {
307
+ options,
308
+ context: {
309
+ nextPageToken,
310
+ },
311
+ };
312
+ },
313
+ },
314
+ adGroupId: {
315
+ type: "string",
316
+ label: "Ad Group",
317
+ description: "Numeric ad group ID (e.g., `1234567890`). Use the **List Ad Groups** action to discover valid IDs.",
318
+ useQuery: true,
319
+ async options({
320
+ accountId, customerClientId, query, prevContext,
321
+ }) {
322
+ const pageToken = prevContext?.nextPageToken;
323
+ const {
324
+ results, nextPageToken,
325
+ } = await this.listResources({
326
+ accountId,
327
+ customerClientId,
328
+ resource: "ad_group",
329
+ query,
330
+ pageToken,
331
+ });
332
+ const options = results?.map?.((item) => this.getResourceOption(item, "ad_group")) ?? [];
333
+ return {
334
+ options,
335
+ context: {
336
+ nextPageToken,
337
+ },
338
+ };
339
+ },
340
+ },
341
+ campaignBudgetId: {
342
+ type: "string",
343
+ label: "Campaign Budget",
344
+ description: "Numeric budget ID (e.g., `1234567890`). Use the **List Campaign Budgets** action to discover valid IDs.",
345
+ useQuery: true,
346
+ async options({
347
+ accountId, customerClientId, query, prevContext,
348
+ }) {
349
+ const pageToken = prevContext?.nextPageToken;
350
+ const {
351
+ results, nextPageToken,
352
+ } = await this.listAllCampaignBudgets({
353
+ accountId,
354
+ customerClientId,
355
+ query,
356
+ pageToken,
357
+ });
358
+ const options = results?.map?.((item) => ({
359
+ label: item.campaignBudget?.name ?? `Budget ${item.campaignBudget?.id}`,
360
+ value: item.campaignBudget?.id,
361
+ })) ?? [];
362
+ return {
363
+ options,
364
+ context: {
365
+ nextPageToken,
366
+ },
367
+ };
368
+ },
369
+ },
370
+ campaignCriterionId: {
371
+ type: "string",
372
+ label: "Campaign Criterion",
373
+ description: "Campaign criterion resource name (e.g., `customers/123/campaignCriteria/456~789`). Use the **List Campaign Criteria** action to discover valid values.",
374
+ useQuery: true,
375
+ async options({
376
+ accountId, customerClientId, query, prevContext,
377
+ }) {
378
+ const pageToken = prevContext?.nextPageToken;
379
+ const {
380
+ results, nextPageToken,
381
+ } = await this.listCampaignCriteria({
382
+ accountId,
383
+ customerClientId,
384
+ query,
385
+ pageToken,
386
+ });
387
+ const options = results?.map?.((item) => {
388
+ const criterion = item.campaignCriterion;
389
+ const campaignName = item.campaign?.name;
390
+ let criterionLabel;
391
+ if (criterion?.type === "KEYWORD") {
392
+ criterionLabel = `[${criterion.keyword?.matchType}] ${criterion.keyword?.text}`;
393
+ } else {
394
+ criterionLabel = `[${criterion?.type}] ${criterion?.criterionId}`;
395
+ }
396
+ return {
397
+ label: `${criterionLabel} (${campaignName})`,
398
+ value: criterion?.resourceName,
399
+ };
400
+ }) ?? [];
401
+ return {
402
+ options,
403
+ context: {
404
+ nextPageToken,
405
+ },
406
+ };
407
+ },
408
+ },
409
+ biddingStrategyId: {
410
+ type: "string",
411
+ label: "Bidding Strategy",
412
+ description: "Numeric bidding strategy ID (e.g., `1234567890`). Use the **List Bidding Strategies** action to discover valid IDs.",
413
+ useQuery: true,
414
+ async options({
415
+ accountId, customerClientId, query, prevContext,
416
+ }) {
417
+ const pageToken = prevContext?.nextPageToken;
418
+ const {
419
+ results, nextPageToken,
420
+ } = await this.listAllBiddingStrategies({
421
+ accountId,
422
+ customerClientId,
423
+ query,
424
+ pageToken,
425
+ });
426
+ const options = results?.map?.((item) => ({
427
+ label: `[${item.biddingStrategy?.type}] ${item.biddingStrategy?.name}`,
428
+ value: item.biddingStrategy?.id,
429
+ })) ?? [];
430
+ return {
431
+ options,
432
+ context: {
433
+ nextPageToken,
434
+ },
435
+ };
436
+ },
437
+ },
438
+ conversionActionId: {
439
+ type: "string",
440
+ label: "Conversion Action",
441
+ description: "The conversion action to record this conversion against, as a resource name (e.g. `customers/1234567890/conversionActions/987654321`). Use a value returned by this selector. Must be an upload-type action (**Upload Clicks** for click conversions, **Upload Calls** for call conversions) - create one with the **Send Offline Conversion** action.",
442
+ async options({
443
+ accountId, customerClientId, prevContext,
444
+ }) {
445
+ const pageToken = prevContext?.nextPageToken;
446
+ const {
447
+ results, nextPageToken,
448
+ } = await this.search({
449
+ query: QUERIES.listConversionActions(),
450
+ accountId,
451
+ customerClientId,
452
+ params: {
453
+ pageToken,
454
+ },
455
+ });
456
+ const options = results?.map(({
457
+ conversionAction: {
458
+ resourceName, name,
459
+ },
460
+ }) => ({
461
+ label: name,
462
+ value: resourceName,
463
+ })) ?? [];
464
+ return {
465
+ options,
466
+ context: {
467
+ nextPageToken,
468
+ },
469
+ };
470
+ },
471
+ },
127
472
  leadFormId: {
128
473
  type: "string",
129
474
  label: "Lead Form ID",
130
- description: "Select a [Lead Form](https://developers.google.com/google-ads/api/reference/rpc/v21/LeadFormAsset) to watch for new entries.",
475
+ description: "Select a [Lead Form](https://developers.google.com/google-ads/api/reference/rpc/v25/LeadFormAsset) to watch for new entries.",
131
476
  async options({
132
477
  accountId, customerClientId,
133
478
  }) {
@@ -144,7 +489,7 @@ export default {
144
489
  }) => ({
145
490
  label: `${businessName} - ${headline}`,
146
491
  value: id,
147
- }));
492
+ })) ?? [];
148
493
  },
149
494
  },
150
495
  },
@@ -164,7 +509,7 @@ export default {
164
509
  }) {
165
510
  const data = {
166
511
  headers: this._headers(accountId),
167
- path: path.replace("{customerClientId}", customerClientId ?? accountId),
512
+ path: `/${API_VERSION}${path.replace("{customerClientId}", customerClientId ?? accountId)}`,
168
513
  ...opts,
169
514
  };
170
515
  return axios($, {
@@ -178,7 +523,7 @@ export default {
178
523
  }) {
179
524
  console.log("Executing query: ", query);
180
525
  const response = await this._makeRequest({
181
- path: "/v21/customers/{customerClientId}/googleAds:search",
526
+ path: "/customers/{customerClientId}/googleAds:search",
182
527
  method: "post",
183
528
  data: {
184
529
  query,
@@ -189,7 +534,7 @@ export default {
189
534
  },
190
535
  async listAccessibleCustomers() {
191
536
  const response = await this._makeRequest({
192
- path: "/v21/customers:listAccessibleCustomers",
537
+ path: "/customers:listAccessibleCustomers",
193
538
  });
194
539
  return response.resourceNames;
195
540
  },
@@ -208,7 +553,7 @@ export default {
208
553
  },
209
554
  async createUserList(args) {
210
555
  const response = await this._makeRequest({
211
- path: "/v21/customers/{customerClientId}/userLists:mutate",
556
+ path: "/customers/{customerClientId}/userLists:mutate",
212
557
  method: "post",
213
558
  ...args,
214
559
  });
@@ -273,25 +618,39 @@ export default {
273
618
  },
274
619
  async createConversionAction(args) {
275
620
  const response = await this._makeRequest({
276
- path: "/v21/customers/{customerClientId}/conversionActions:mutate",
621
+ path: "/customers/{customerClientId}/conversionActions:mutate",
277
622
  method: "post",
278
623
  ...args,
279
624
  });
280
625
  return response;
281
626
  },
627
+ async uploadClickConversions(opts = {}) {
628
+ return this._makeRequest({
629
+ method: "POST",
630
+ path: "/customers/{customerClientId}:uploadClickConversions",
631
+ ...opts,
632
+ });
633
+ },
634
+ async uploadCallConversions(opts = {}) {
635
+ return this._makeRequest({
636
+ method: "POST",
637
+ path: "/customers/{customerClientId}:uploadCallConversions",
638
+ ...opts,
639
+ });
640
+ },
282
641
  async addContactToCustomerList({
283
642
  path, ...opts
284
643
  }) {
285
644
  return this._makeRequest({
286
645
  method: "POST",
287
- path: `/v21/${path}:addOperations`,
646
+ path: `/${path}:addOperations`,
288
647
  ...opts,
289
648
  });
290
649
  },
291
650
  async createOfflineUserDataJob(opts = {}) {
292
651
  return this._makeRequest({
293
652
  method: "POST",
294
- path: "/v21/customers/{customerClientId}/offlineUserDataJobs:create",
653
+ path: "/customers/{customerClientId}/offlineUserDataJobs:create",
295
654
  ...opts,
296
655
  });
297
656
  },
@@ -300,16 +659,295 @@ export default {
300
659
  }) {
301
660
  return this._makeRequest({
302
661
  method: "POST",
303
- path: `/v21/${path}:run`,
662
+ path: `/${path}:run`,
304
663
  ...args,
305
664
  });
306
665
  },
307
666
  async generateKeywordIdeas(opts = {}) {
308
667
  return this._makeRequest({
309
668
  method: "POST",
310
- path: "/v22/customers/{customerClientId}:generateKeywordIdeas",
669
+ path: "/customers/{customerClientId}:generateKeywordIdeas",
670
+ ...opts,
671
+ });
672
+ },
673
+ async mutateCampaign(opts = {}) {
674
+ return this._makeRequest({
675
+ method: "POST",
676
+ path: "/customers/{customerClientId}/campaigns:mutate",
311
677
  ...opts,
312
678
  });
313
679
  },
680
+ async mutateAdGroup(opts = {}) {
681
+ return this._makeRequest({
682
+ method: "POST",
683
+ path: "/customers/{customerClientId}/adGroups:mutate",
684
+ ...opts,
685
+ });
686
+ },
687
+ async listAllCampaigns({
688
+ query, pageToken, ...args
689
+ }) {
690
+ const filter = query
691
+ ? ` WHERE campaign.name LIKE '%${sanitizeGaqlString(query)}%'`
692
+ : "";
693
+ return this.search({
694
+ query: `SELECT campaign.id, campaign.name, campaign.status, campaign.advertising_channel_type, campaign.start_date_time, campaign.end_date_time FROM campaign${filter}`,
695
+ params: {
696
+ pageToken,
697
+ },
698
+ ...args,
699
+ });
700
+ },
701
+ async listAllAdGroups({
702
+ query, pageToken, ...args
703
+ }) {
704
+ const filter = query
705
+ ? ` WHERE ad_group.name LIKE '%${sanitizeGaqlString(query)}%'`
706
+ : "";
707
+ return this.search({
708
+ query: `SELECT ad_group.id, ad_group.name, ad_group.status, ad_group.campaign, ad_group.type FROM ad_group${filter}`,
709
+ params: {
710
+ pageToken,
711
+ },
712
+ ...args,
713
+ });
714
+ },
715
+ async listAllAdGroupAds({
716
+ query, pageToken, ...args
717
+ }) {
718
+ const filter = query
719
+ ? ` WHERE ad_group_ad.ad.name LIKE '%${sanitizeGaqlString(query)}%'`
720
+ : "";
721
+ return this.search({
722
+ query: `SELECT ad_group_ad.resource_name, ad_group_ad.ad.id, ad_group_ad.ad.name, ad_group_ad.ad.type, ad_group_ad.status, ad_group.id, ad_group.name FROM ad_group_ad${filter}`,
723
+ params: {
724
+ pageToken,
725
+ },
726
+ ...args,
727
+ });
728
+ },
729
+ async listAllKeywords({
730
+ query, pageToken, ...args
731
+ }) {
732
+ const filter = query
733
+ ? ` AND ad_group_criterion.keyword.text LIKE '%${sanitizeGaqlString(query)}%'`
734
+ : "";
735
+ return this.search({
736
+ query: `SELECT ad_group_criterion.criterion_id, ad_group_criterion.resource_name, ad_group_criterion.keyword.text, ad_group_criterion.keyword.match_type, ad_group_criterion.status, ad_group_criterion.cpc_bid_micros, ad_group_criterion.negative, ad_group.id, ad_group.name FROM ad_group_criterion WHERE ad_group_criterion.type = 'KEYWORD'${filter}`,
737
+ params: {
738
+ pageToken,
739
+ },
740
+ ...args,
741
+ });
742
+ },
743
+ async listKeywords({
744
+ query, pageToken, ...args
745
+ }) {
746
+ const filter = query
747
+ ? ` AND ad_group_criterion.keyword.text LIKE '%${sanitizeGaqlString(query)}%'`
748
+ : "";
749
+ return this.search({
750
+ query: `SELECT ad_group_criterion.resource_name, ad_group_criterion.keyword.text, ad_group_criterion.keyword.match_type FROM ad_group_criterion WHERE ad_group_criterion.type = 'KEYWORD'${filter}`,
751
+ params: {
752
+ pageToken,
753
+ },
754
+ ...args,
755
+ });
756
+ },
757
+ async mutateAdGroupCriteria(opts = {}) {
758
+ return this._makeRequest({
759
+ method: "POST",
760
+ path: "/customers/{customerClientId}/adGroupCriteria:mutate",
761
+ ...opts,
762
+ });
763
+ },
764
+ async mutateAdGroupAd(opts = {}) {
765
+ return this._makeRequest({
766
+ method: "POST",
767
+ path: "/customers/{customerClientId}/adGroupAds:mutate",
768
+ ...opts,
769
+ });
770
+ },
771
+ async listAllSharedSets({
772
+ query, pageToken, ...args
773
+ }) {
774
+ const filter = query
775
+ ? ` AND shared_set.name LIKE '%${sanitizeGaqlString(query)}%'`
776
+ : "";
777
+ return this.search({
778
+ query: `SELECT shared_set.id, shared_set.name, shared_set.type, shared_set.status FROM shared_set WHERE shared_set.status = 'ENABLED'${filter}`,
779
+ params: {
780
+ pageToken,
781
+ },
782
+ ...args,
783
+ });
784
+ },
785
+ async mutateSharedSets(opts = {}) {
786
+ return this._makeRequest({
787
+ method: "POST",
788
+ path: "/customers/{customerClientId}/sharedSets:mutate",
789
+ ...opts,
790
+ });
791
+ },
792
+ async listSharedCriteria({
793
+ query, pageToken, ...args
794
+ }) {
795
+ const filter = query
796
+ ? ` AND shared_criterion.keyword.text LIKE '%${sanitizeGaqlString(query)}%'`
797
+ : "";
798
+ return this.search({
799
+ query: `SELECT shared_criterion.resource_name, shared_criterion.criterion_id, shared_criterion.type, shared_criterion.keyword.text, shared_criterion.keyword.match_type, shared_set.id, shared_set.name FROM shared_criterion WHERE shared_criterion.type = 'KEYWORD'${filter}`,
800
+ params: {
801
+ pageToken,
802
+ },
803
+ ...args,
804
+ });
805
+ },
806
+ async mutateSharedCriteria(opts = {}) {
807
+ return this._makeRequest({
808
+ method: "POST",
809
+ path: "/customers/{customerClientId}/sharedCriteria:mutate",
810
+ ...opts,
811
+ });
812
+ },
813
+ async listCampaignSharedSets({
814
+ query, pageToken, ...args
815
+ }) {
816
+ const filter = query
817
+ ? ` AND (campaign.name LIKE '%${sanitizeGaqlString(query)}%' OR shared_set.name LIKE '%${sanitizeGaqlString(query)}%')`
818
+ : "";
819
+ return this.search({
820
+ query: `SELECT campaign_shared_set.resource_name, campaign_shared_set.status, campaign.id, campaign.name, shared_set.id, shared_set.name FROM campaign_shared_set WHERE campaign_shared_set.status = 'ENABLED'${filter}`,
821
+ params: {
822
+ pageToken,
823
+ },
824
+ ...args,
825
+ });
826
+ },
827
+ async mutateCampaignSharedSets(opts = {}) {
828
+ return this._makeRequest({
829
+ method: "POST",
830
+ path: "/customers/{customerClientId}/campaignSharedSets:mutate",
831
+ ...opts,
832
+ });
833
+ },
834
+ async listAllSharedCriteria({
835
+ query, pageToken, ...args
836
+ }) {
837
+ const filter = query
838
+ ? ` WHERE shared_set.name LIKE '%${sanitizeGaqlString(query)}%'`
839
+ : "";
840
+ return this.search({
841
+ query: `SELECT shared_criterion.resource_name, shared_criterion.criterion_id, shared_criterion.type, shared_criterion.keyword.text, shared_criterion.keyword.match_type, shared_set.id, shared_set.name FROM shared_criterion${filter}`,
842
+ params: {
843
+ pageToken,
844
+ },
845
+ ...args,
846
+ });
847
+ },
848
+ async listAllAdGroupCriteria({
849
+ query, pageToken, ...args
850
+ }) {
851
+ const filter = query
852
+ ? ` WHERE ad_group.name LIKE '%${sanitizeGaqlString(query)}%'`
853
+ : "";
854
+ return this.search({
855
+ query: `SELECT ad_group_criterion.criterion_id, ad_group_criterion.resource_name, ad_group_criterion.type, ad_group_criterion.status, ad_group_criterion.negative, ad_group_criterion.keyword.text, ad_group_criterion.keyword.match_type, ad_group_criterion.cpc_bid_micros, ad_group.id, ad_group.name FROM ad_group_criterion${filter}`,
856
+ params: {
857
+ pageToken,
858
+ },
859
+ ...args,
860
+ });
861
+ },
862
+ async listAllCampaignBudgets({
863
+ query, pageToken, ...args
864
+ }) {
865
+ const filter = query
866
+ ? ` AND campaign_budget.name LIKE '%${sanitizeGaqlString(query)}%'`
867
+ : "";
868
+ return this.search({
869
+ query: `SELECT campaign_budget.id, campaign_budget.name, campaign_budget.amount_micros, campaign_budget.delivery_method, campaign_budget.period, campaign_budget.status FROM campaign_budget WHERE campaign_budget.status = 'ENABLED'${filter}`,
870
+ params: {
871
+ pageToken,
872
+ },
873
+ ...args,
874
+ });
875
+ },
876
+ async mutateCampaignBudgets(opts = {}) {
877
+ return this._makeRequest({
878
+ method: "POST",
879
+ path: "/customers/{customerClientId}/campaignBudgets:mutate",
880
+ ...opts,
881
+ });
882
+ },
883
+ async listCampaignCriteria({
884
+ query, pageToken, ...args
885
+ }) {
886
+ const filter = query
887
+ ? ` AND campaign.name LIKE '%${sanitizeGaqlString(query)}%'`
888
+ : "";
889
+ return this.search({
890
+ query: `SELECT campaign_criterion.resource_name, campaign_criterion.criterion_id, campaign_criterion.type, campaign_criterion.status, campaign_criterion.negative, campaign_criterion.keyword.text, campaign_criterion.keyword.match_type, campaign.id, campaign.name FROM campaign_criterion WHERE campaign_criterion.type = 'KEYWORD'${filter}`,
891
+ params: {
892
+ pageToken,
893
+ },
894
+ ...args,
895
+ });
896
+ },
897
+ async mutateCampaignCriteria(opts = {}) {
898
+ return this._makeRequest({
899
+ method: "POST",
900
+ path: "/customers/{customerClientId}/campaignCriteria:mutate",
901
+ ...opts,
902
+ });
903
+ },
904
+ async listAllCampaignCriteria({
905
+ query, pageToken, ...args
906
+ }) {
907
+ const filter = query
908
+ ? ` WHERE campaign.name LIKE '%${sanitizeGaqlString(query)}%'`
909
+ : "";
910
+ return this.search({
911
+ query: `SELECT campaign_criterion.resource_name, campaign_criterion.criterion_id, campaign_criterion.type, campaign_criterion.status, campaign_criterion.negative, campaign_criterion.keyword.text, campaign_criterion.keyword.match_type, campaign.id, campaign.name FROM campaign_criterion${filter}`,
912
+ params: {
913
+ pageToken,
914
+ },
915
+ ...args,
916
+ });
917
+ },
918
+ async listAllBiddingStrategies({
919
+ query, pageToken, ...args
920
+ }) {
921
+ const filter = query
922
+ ? ` AND bidding_strategy.name LIKE '%${sanitizeGaqlString(query)}%'`
923
+ : "";
924
+ return this.search({
925
+ query: `SELECT bidding_strategy.id, bidding_strategy.name, bidding_strategy.type, bidding_strategy.status FROM bidding_strategy WHERE bidding_strategy.status = 'ENABLED'${filter}`,
926
+ params: {
927
+ pageToken,
928
+ },
929
+ ...args,
930
+ });
931
+ },
932
+ async mutateBiddingStrategies(opts = {}) {
933
+ return this._makeRequest({
934
+ method: "POST",
935
+ path: "/customers/{customerClientId}/biddingStrategies:mutate",
936
+ ...opts,
937
+ });
938
+ },
939
+ async listKeywordQualityScores({
940
+ campaignId, adGroupId, dateRange, ...args
941
+ }) {
942
+ const conditions = [
943
+ `segments.date DURING ${dateRange ?? "LAST_30_DAYS"}`,
944
+ ];
945
+ if (campaignId) conditions.push(`campaign.id = ${Number(campaignId)}`);
946
+ if (adGroupId) conditions.push(`ad_group.id = ${Number(adGroupId)}`);
947
+ return this.search({
948
+ query: `SELECT keyword_view.resource_name, ad_group_criterion.keyword.text, ad_group_criterion.keyword.match_type, ad_group_criterion.status, ad_group_criterion.quality_info.quality_score, ad_group_criterion.quality_info.creative_quality_score, ad_group_criterion.quality_info.post_click_quality_score, ad_group_criterion.quality_info.search_predicted_ctr, metrics.historical_quality_score, metrics.historical_creative_quality_score, metrics.historical_landing_page_quality_score, metrics.historical_search_predicted_ctr, ad_group.id, ad_group.name, campaign.id, campaign.name FROM keyword_view WHERE ${conditions.join(" AND ")}`,
949
+ ...args,
950
+ });
951
+ },
314
952
  },
315
953
  };