//native
type Pinterest = {
token: string;
};
/**
* Get targeting analytics for ad groups
* Get targeting analytics for one or more ad groups.
*/
export async function main(
auth: Pinterest,
ad_account_id: string,
ad_group_ids: string | undefined,
start_date: string | undefined,
end_date: string | undefined,
targeting_types: string | undefined,
columns: string | undefined,
granularity: "TOTAL" | "DAY" | "HOUR" | "WEEK" | "MONTH" | undefined,
click_window_days: "0" | "1" | "7" | "14" | "30" | "60" | undefined,
engagement_window_days: "0" | "1" | "7" | "14" | "30" | "60" | undefined,
view_window_days: "0" | "1" | "7" | "14" | "30" | "60" | undefined,
conversion_report_time:
| "TIME_OF_AD_ACTION"
| "TIME_OF_CONVERSION"
| undefined,
attribution_types: "INDIVIDUAL" | "HOUSEHOLD" | undefined,
) {
const url = new URL(
`https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ad_groups/targeting_analytics`,
);
for (const [k, v] of [
["ad_group_ids", ad_group_ids],
["start_date", start_date],
["end_date", end_date],
["targeting_types", targeting_types],
["columns", columns],
["granularity", granularity],
["click_window_days", click_window_days],
["engagement_window_days", engagement_window_days],
["view_window_days", view_window_days],
["conversion_report_time", conversion_report_time],
["attribution_types", attribution_types],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago