Skip to content

Commit

Permalink
Merge pull request #481 from Opteo/handle-policy-exemptions
Browse files Browse the repository at this point in the history
feat(service): allow policy violation exemptions
  • Loading branch information
Josecamero authored Nov 15, 2023
2 parents 0ff8d1f + 4683319 commit b49f93b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,51 @@ const result = await customer.mutateResources(operations);

---

## Add Policy Exemption Rules

```ts
import {
resources,
enums,
toMicros,
ResourceNames,
MutateOperation,
} from "google-ads-api";

// Ad Group to which you want to add the keyword
const adGroupResourceName = 'customers/123/adGroups/456'

const keyword = '24 hour locksmith harlem'

const operations: MutateOperation<
resources.IAdGroupCriterion & { exempt_policy_violation_keys?: google.ads.googleads.v14.common.IPolicyViolationKey[]}
>[] = [
{
entity: 'ad_group_criterion',
operation: "create",
resource: {
// Keyword with policy violation exemptions
ad_group: adGroupResourceName,
keyword: {
text: '24 hour locksmith harlem',
match_type: enums.KeywordMatchType.PHRASE,
},
status: enums.AdGroupStatus.ENABLED ,
},
exempt_policy_violation_keys: [
{
policy_name: 'LOCAL_SERVICES',
violating_text: keyword,
},
],
}
];

const result = await customer.mutateResources(operations);
```

---

## Uploading Click Conversions

```ts
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-ads-api",
"version": "14.1.0",
"version": "14.2.0",
"description": "Google Ads API Client Library for Node.js",
"repository": "https://github.com/Opteo/google-ads-api",
"main": "build/src/index.js",
Expand Down
9 changes: 6 additions & 3 deletions scripts/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,19 @@ function buildMutateMethod(
): string {
const isUpdate = mutation === "update";
const updateMaskMessageArg = isUpdate ? `, ${requestClass}` : "";

const policyViolationArgType =
argName !== "adGroupCriteria"
? `(${resourceType} | ${requestClass})[]`
: `((${resourceType} & {exempt_policy_violation_keys?: services.AdGroupCriterionOperation['exempt_policy_violation_keys'] } ) | (${requestClass} & {exempt_policy_violation_keys?: services.AdGroupCriterionOperation['exempt_policy_violation_keys'] }))[]`;
return `
/**
* @description ${mutation} resources of type ${resourceType}
* @returns ${responseType}
*/
${mutation}: async (
${argName}: ${
mutation === "remove"
? `${resourceType}[]`
: `(${resourceType} | ${requestClass})[]`
mutation === "remove" ? `${resourceType}[]` : `${policyViolationArgType}`
} ,
options?: MutateOptions
): Promise<${responseType} > => {
Expand Down
16 changes: 12 additions & 4 deletions src/protos/autogen/serviceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1926,8 +1926,12 @@ export default class ServiceFactory extends Service {
*/
create: async (
adGroupCriteria: (
| resources.IAdGroupCriterion
| resources.AdGroupCriterion
| (resources.IAdGroupCriterion & {
exempt_policy_violation_keys?: services.AdGroupCriterionOperation["exempt_policy_violation_keys"];
})
| (resources.AdGroupCriterion & {
exempt_policy_violation_keys?: services.AdGroupCriterionOperation["exempt_policy_violation_keys"];
})
)[],
options?: MutateOptions
): Promise<services.MutateAdGroupCriteriaResponse> => {
Expand Down Expand Up @@ -2006,8 +2010,12 @@ export default class ServiceFactory extends Service {
*/
update: async (
adGroupCriteria: (
| resources.IAdGroupCriterion
| resources.AdGroupCriterion
| (resources.IAdGroupCriterion & {
exempt_policy_violation_keys?: services.AdGroupCriterionOperation["exempt_policy_violation_keys"];
})
| (resources.AdGroupCriterion & {
exempt_policy_violation_keys?: services.AdGroupCriterionOperation["exempt_policy_violation_keys"];
})
)[],
options?: MutateOptions
): Promise<services.MutateAdGroupCriteriaResponse> => {
Expand Down
18 changes: 16 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ export class Service {
const operation = {
[mutation.operation ?? "create"]: mutation.resource,
};
if (mutation.operation === "update") {
if (
mutation.operation === "create" &&
//@ts-ignore
mutation?.exempt_policy_violation_keys?.length
) {
//@ts-ignore
operation.exempt_policy_violation_keys =
mutation.exempt_policy_violation_keys;
} else if (mutation.operation === "update") {
// @ts-expect-error Resource operations should have updateMask defined
operation.update_mask = getFieldMask(mutation.resource);
}
Expand Down Expand Up @@ -237,7 +245,13 @@ export class Service {
[type]: e,
operation: type,
};
if (type === "update") {
//@ts-ignore
if (type === "create" && e?.exempt_policy_violation_keys?.length) {
// @ts-expect-error Field required for policy violation exemptions
op.exempt_policy_violation_keys = e.exempt_policy_violation_keys;
//@ts-ignore
delete e.exempt_policy_violation_keys;
} else if (type === "update") {
// @ts-expect-error Field required for updates
op.update_mask = getFieldMask(
// @ts-expect-error Message types have a toObject method
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type MutateOperation<T> = {
resource: T;
entity: fields.Resource;
operation?: "create" | "update" | "remove";
exempt_policy_violation_keys?: services.AdGroupCriterionOperation["exempt_policy_violation_keys"];
} & Partial<Omit<T, "toJSON">>;

export type PageToken = services.ISearchGoogleAdsResponse["next_page_token"];

0 comments on commit b49f93b

Please sign in to comment.