//native
type Klaviyo = {
apiKey: string;
};
/**
* Update Tracking Setting
* Update the tracking setting with the given account ID.*Rate limits*:Burst: `10/s`Steady: `150/m`
*/
export async function main(
auth: Klaviyo,
id: string,
revision: string,
body: {
data: {
type: "tracking-setting";
id: string;
attributes: {
auto_add_parameters?: false | true;
utm_source?: {
flow?:
| {
type: "dynamic";
value:
| "email_subject"
| "flow_id"
| "flow_name"
| "link_alt_text"
| "message_name"
| "message_name_id"
| "message_type"
| "profile_external_id"
| "profile_id";
}
| { type: "static"; value: string };
campaign?:
| {
type: "dynamic";
value:
| "email_subject"
| "link_alt_text"
| "message_type"
| "profile_external_id"
| "profile_id"
| "campaign_id"
| "campaign_name"
| "campaign_name_id"
| "campaign_name_send_day"
| "group_id"
| "group_name"
| "group_name_id";
}
| { type: "static"; value: string };
};
utm_medium?: {
flow?:
| {
type: "dynamic";
value:
| "email_subject"
| "flow_id"
| "flow_name"
| "link_alt_text"
| "message_name"
| "message_name_id"
| "message_type"
| "profile_external_id"
| "profile_id";
}
| { type: "static"; value: string };
campaign?:
| {
type: "dynamic";
value:
| "email_subject"
| "link_alt_text"
| "message_type"
| "profile_external_id"
| "profile_id"
| "campaign_id"
| "campaign_name"
| "campaign_name_id"
| "campaign_name_send_day"
| "group_id"
| "group_name"
| "group_name_id";
}
| { type: "static"; value: string };
};
utm_campaign?: {
flow?:
| {
type: "dynamic";
value:
| "email_subject"
| "flow_id"
| "flow_name"
| "link_alt_text"
| "message_name"
| "message_name_id"
| "message_type"
| "profile_external_id"
| "profile_id";
}
| { type: "static"; value: string };
campaign?:
| {
type: "dynamic";
value:
| "email_subject"
| "link_alt_text"
| "message_type"
| "profile_external_id"
| "profile_id"
| "campaign_id"
| "campaign_name"
| "campaign_name_id"
| "campaign_name_send_day"
| "group_id"
| "group_name"
| "group_name_id";
}
| { type: "static"; value: string };
};
utm_id?: {
flow?:
| {
type: "dynamic";
value:
| "email_subject"
| "flow_id"
| "flow_name"
| "link_alt_text"
| "message_name"
| "message_name_id"
| "message_type"
| "profile_external_id"
| "profile_id";
}
| { type: "static"; value: string };
campaign?:
| {
type: "dynamic";
value:
| "email_subject"
| "link_alt_text"
| "message_type"
| "profile_external_id"
| "profile_id"
| "campaign_id"
| "campaign_name"
| "campaign_name_id"
| "campaign_name_send_day"
| "group_id"
| "group_name"
| "group_name_id";
}
| { type: "static"; value: string };
};
utm_term?: {
flow?:
| {
type: "dynamic";
value:
| "email_subject"
| "flow_id"
| "flow_name"
| "link_alt_text"
| "message_name"
| "message_name_id"
| "message_type"
| "profile_external_id"
| "profile_id";
}
| { type: "static"; value: string };
campaign?:
| {
type: "dynamic";
value:
| "email_subject"
| "link_alt_text"
| "message_type"
| "profile_external_id"
| "profile_id"
| "campaign_id"
| "campaign_name"
| "campaign_name_id"
| "campaign_name_send_day"
| "group_id"
| "group_name"
| "group_name_id";
}
| { type: "static"; value: string };
};
custom_parameters?: {
flow?:
| {
type: "dynamic";
value:
| "email_subject"
| "flow_id"
| "flow_name"
| "link_alt_text"
| "message_name"
| "message_name_id"
| "message_type"
| "profile_external_id"
| "profile_id";
}
| { type: "static"; value: string };
campaign?:
| {
type: "dynamic";
value:
| "email_subject"
| "link_alt_text"
| "message_type"
| "profile_external_id"
| "profile_id"
| "campaign_id"
| "campaign_name"
| "campaign_name_id"
| "campaign_name_send_day"
| "group_id"
| "group_name"
| "group_name_id";
}
| { type: "static"; value: string };
name: string;
}[];
};
};
},
) {
const url = new URL(`https://a.klaviyo.com/api/tracking-settings/${id}`);
const response = await fetch(url, {
method: "PATCH",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
"Content-Type": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago