Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamsharif committed Jul 17, 2024
1 parent 8ca37e7 commit 0d665eb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
QueryResponse,
ConversionActionId,
ConversionActionResponse,
CustomVariableInterface
CustomVariableInterface,
CreateAudienceInput,
CreateGoogleAudienceResponse,
AudienceSettings,
UserListResponse,
UserList
} from './types'
import {
ModifiedResponse,
Expand All @@ -25,35 +30,13 @@ export const API_VERSION = 'v16'
export const CANARY_API_VERSION = 'v16'
export const FLAGON_NAME = 'google-enhanced-canary-version'

export interface AudienceSettings {
external_id_type: string
}
export interface GoogleAdsResonse {
resourceName?: string
}
export interface CreateGoogleAudienceResponse {
resourceName?: string
results: Array<{ resourceName: string }>
}
export class GoogleAdsError extends HTTPError {
response: Response & {
status: string
statusText: string
}
}

export interface CreateAudienceInput {
audienceName: string
settings: {
customerId?: string
conversionTrackingId?: string
}
audienceSettings: {
external_id_type: string
app_id?: string
}
}

export function formatCustomVariables(
customVariables: object,
customVariableIdsResults: Array<ConversionCustomVariable>
Expand Down Expand Up @@ -215,19 +198,35 @@ export async function getListIds(request: RequestClient, settings: CreateAudienc
query: `SELECT user_list.id, user_list.name FROM user_list`
}

const response = await request(
`https://googleads.googleapis.com/${API_VERSION}/customers/${settings.customerId}/googleAds:search`,
{
method: 'post',
headers: {
'developer-token': `${process.env.ADWORDS_DEVELOPER_TOKEN}`,
authorization: `Bearer ${auth?.accessToken}`
},
json
}
)
try {
const response: ModifiedResponse<UserListResponse> = await request(
`https://googleads.googleapis.com/${API_VERSION}/customers/${settings.customerId}/googleAds:search`,
{
method: 'post',
headers: {
'developer-token': `${process.env.ADWORDS_DEVELOPER_TOKEN}`,
authorization: `Bearer ${auth?.accessToken}`
},
json
}
)

return (response.data as any).results
const choices = response.data.results.map((input: UserList) => {
return { value: input.userList.id, label: input.userList.name }
})
return {
choices
}
} catch (err) {
return {
choices: [],
nextPage: '',
error: {
message: (err as GoogleAdsError).response?.statusText ?? 'Unknown error',
code: (err as GoogleAdsError).response?.status + '' ?? '500'
}
}
}
}

export async function createGoogleAudience(
Expand Down Expand Up @@ -258,7 +257,7 @@ export async function createGoogleAudience(
}

const response = await request(
`https://googleads.googleapis.com/${API_VERSION}/customers/${input.settings.customerId}:mutate`,
`https://googleads.googleapis.com/${API_VERSION}/customers/${input.settings.customerId}/userLists:mutate`,
{
method: 'post',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import postConversion from './postConversion'
import uploadCallConversion from './uploadCallConversion'
import uploadClickConversion from './uploadClickConversion'
import uploadConversionAdjustment from './uploadConversionAdjustment'
import { CreateAudienceInput, createGoogleAudience, getGoogleAudience } from './functions'
import { CreateAudienceInput } from './types'
import { createGoogleAudience, getGoogleAudience } from './functions'

import userList from './userList'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,37 @@ export interface PartialErrorResponse {
}
results: {}[]
}

export interface UserList {
userList: {
resourceName: string
id: string
name: string
}
}

export interface UserListResponse {
results: Array<UserList>
fieldMask: string
}

export interface CreateAudienceInput {
audienceName: string
settings: {
customerId?: string
conversionTrackingId?: string
}
audienceSettings: {
external_id_type: string
app_id?: string
}
}

export interface CreateGoogleAudienceResponse {
resourceName?: string
results: Array<{ resourceName: string }>
}

export interface AudienceSettings {
external_id_type: string
}

0 comments on commit 0d665eb

Please sign in to comment.