Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update google ads api to v15 #556

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/actions/google/ads/lib/ads_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class GoogleAdsActionExecutor {
readonly targetCid = this.adsRequest.targetCid
readonly mobileAppId = this.adsRequest.mobileAppId
readonly uploadKeyType = this.adsRequest.uploadKeyType
readonly consentAdUserData = this.adsRequest.consentAdUserData
readonly consentAdPersonalization = this.adsRequest.consentAdPersonalization
offlineUserDataJobResourceName: string
targetUserListRN: string

Expand All @@ -25,7 +27,12 @@ export class GoogleAdsActionExecutor {
}

async createDataJob() {
const createJobResp = await this.apiClient.createDataJob(this.targetCid, this.targetUserListRN)
const createJobResp = await this.apiClient.createDataJob(
this.targetCid,
this.targetUserListRN,
this.consentAdUserData,
this.consentAdPersonalization,
)
this.offlineUserDataJobResourceName = createJobResp.resourceName
this.log("info", "Created data job:", this.offlineUserDataJobResourceName)
return createJobResp
Expand Down
47 changes: 42 additions & 5 deletions src/actions/google/ads/lib/ads_form_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,25 @@ export class GoogleAdsActionFormBuilder {

// 3) Branch 1: Show the fields for creating a new list (name & desc), plus hashing, and we're done
if (this.isCreate) {
form.fields.push(this.newListNameField())
form.fields.push(this.newListDescriptionField())
form.fields.push(this.doHashingFormField())
form.fields = [
...form.fields,
this.newListNameField(),
this.newListDescriptionField(),
this.doHashingFormField(),
...this.consentSetting(),
]
return form
}

// 4) Branch 2: Select an existing list, but we need to check that there is at least one to choose...
const userListOptions = await this.getUserListOptions()
if (userListOptions.length) {
form.fields.push(this.targetListField(userListOptions))
form.fields.push(this.doHashingFormField())
form.fields = [
...form.fields,
this.targetListField(userListOptions),
this.doHashingFormField(),
...this.consentSetting(),
]
} else {
form.fields.push(this.noAvailableListsField())
}
Expand Down Expand Up @@ -261,6 +269,35 @@ export class GoogleAdsActionFormBuilder {
}
}

consentSetting() {
return [
{
name: "consentAdUserData",
label: "Step 5) The consent setting for consent for ad user data",
type: "select" as "select",
options: [
{name: "UNSPECIFIED", label: "Unspecified"},
{name: "GRANTED", label: "Granted"},
{name: "DENIED", label: "Denied"},
],
default: "UNSPECIFIED",
required: true,
},
{
name: "consentAdPersonalization",
label: "The consent setting for consent for ad personalization",
type: "select" as "select",
options: [
{name: "UNSPECIFIED", label: "Unspecified"},
{name: "GRANTED", label: "Granted"},
{name: "DENIED", label: "Denied"},
],
default: "UNSPECIFIED",
required: true,
},
]
}

private async maybeSetLoginCustomer() {
if (!this.loginCid) {
return
Expand Down
8 changes: 8 additions & 0 deletions src/actions/google/ads/lib/ads_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ export class GoogleAdsActionRequest {
return this.isMobileDevice ? "MOBILE_ADVERTISING_ID" : "CONTACT_INFO"
}

get consentAdUserData() {
return this.formParams.consentAdUserData
}

get consentAdPersonalization() {
return this.formParams.consentAdPersonalization
}

get developerToken() {
return this.actionInstance.developerToken
}
Expand Down
20 changes: 18 additions & 2 deletions src/actions/google/ads/lib/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import * as lodash from "lodash"
import { sanitizeError as sanitize } from "../../common/error_utils"
import { Logger } from "../../common/logger"

type ConsentType = "UNSPECIFIED" | "GRANTED" | "DENIED"
interface Consent {
ad_user_data: ConsentType
ad_personalization: ConsentType
}

export class GoogleAdsApiClient {

constructor(readonly log: Logger, readonly accessToken: string
Expand Down Expand Up @@ -77,16 +83,26 @@ export class GoogleAdsApiClient {
return this.apiCall(method, path, body)
}

async createDataJob(targetCid: string, userListResourceName: string) {
async createDataJob(
targetCid: string,
userListResourceName: string,
consentAdUserData: ConsentType,
consentAdPersonalization: ConsentType,
) {
const method = "POST"
const path = `customers/${targetCid}/offlineUserDataJobs:create`
const consent: Consent = {
ad_user_data: consentAdUserData,
ad_personalization: consentAdPersonalization,
}
const body = {
customer_id: targetCid,
job: {
external_id: Date.now(), // must be an Int64 so not very useful
type: "CUSTOMER_MATCH_USER_LIST",
customer_match_user_list_metadata: {
user_list: userListResourceName,
consent,
},
},
}
Expand Down Expand Up @@ -129,7 +145,7 @@ export class GoogleAdsApiClient {
url,
data,
headers,
baseURL: "https://googleads.googleapis.com/v14/",
baseURL: "https://googleads.googleapis.com/v15/",
})

if (process.env.ACTION_HUB_DEBUG) {
Expand Down
Loading