0

Create tracking identity and track event

by
Published Oct 17, 2025

Identifies a user and tracks an event with a single API call. The following role is required for this endpoint: org.tracking

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Create tracking identity and track event
7
 * Identifies a user and tracks an event with a single API call.
8

9
The following role is required for this endpoint: org.tracking
10
 */
11
export async function main(
12
  auth: Kustomer,
13
  body: {
14
    identity: {
15
      remember?: false | true;
16
      trackingId?: string;
17
      sessionId?: string;
18
      name?: string;
19
      company?: string;
20
      externalId?: string;
21
      username?: string;
22
      signedUpAt?: string;
23
      birthdayAt?: string;
24
      gender?: "m" | "f";
25
      locale?: string;
26
      timeZone?: string;
27
      email?: string;
28
      phone?: string;
29
      location?: {
30
        type?: "home" | "work" | "other";
31
        name?: string;
32
        address?: string;
33
        address2?: string;
34
        address3?: string;
35
        latitude?: number;
36
        longitude?: number;
37
        countryCode?: string;
38
        countryName?: string;
39
        regionCode?: string;
40
        regionName?: string;
41
        cityName?: string;
42
        zipCode?: string;
43
        areaCode?: string;
44
      };
45
      tags?: string[];
46
      custom?: {};
47
    };
48
    event: { trackingId?: string; sessionId?: string; name: string; meta?: {} };
49
  },
50
) {
51
  const url = new URL(`https://api.kustomerapp.com/v1/tracking/identityEvent`);
52

53
  const response = await fetch(url, {
54
    method: "POST",
55
    headers: {
56
      "Content-Type": "application/json",
57
      Authorization: "Bearer " + auth.apiKey,
58
    },
59
    body: JSON.stringify(body),
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67