0

Create conversion tag

by
Published Dec 20, 2024

Create a conversion tag, also known as Pinterest tag, with the option to enable enhanced match. The Pinterest Tag tracks actions people take on the ad account’ s website after they view the ad account's ad on Pinterest. The advertiser needs to customize this tag to track conversions. For more information, see: Set up the Pinterest tag Pinterest Tag Enhanced match

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Create conversion tag
7
 * Create a conversion tag, also known as Pinterest tag, with the option to enable enhanced match.
8
The Pinterest Tag tracks actions people take on the ad account’ s website after they view the ad account's ad on Pinterest. The advertiser needs to customize this tag to track conversions.
9
For more information, see:
10
Set up the Pinterest tag
11
Pinterest Tag
12
Enhanced match
13
 */
14
export async function main(
15
  auth: Pinterest,
16
  ad_account_id: string,
17
  body: {
18
    aem_enabled?: false | true;
19
    md_frequency?: number;
20
    aem_fnln_enabled?: false | true;
21
    aem_ph_enabled?: false | true;
22
    aem_ge_enabled?: false | true;
23
    aem_db_enabled?: false | true;
24
    aem_loc_enabled?: false | true;
25
  } & { name: string },
26
) {
27
  const url = new URL(
28
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/conversion_tags`,
29
  );
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45