Skip to content

오브젝트 배열

이 페이지에서는 관련 속성을 그룹화하기 위해 오브젝트 배열을 사용하는 방법을 다룹니다. 예를 들어, 한 사용자에게 속하는 반려동물 오브젝트, 노래 오브젝트, 계정 오브젝트 그룹이 있을 수 있습니다. 이러한 오브젝트 배열은 Liquid를 사용하여 메시징을 개인화하거나, 오브젝트 내의 요소가 기준과 일치하는 경우 오디언스 세그먼트를 생성하는 데 사용할 수 있습니다.

Supported data types

다음 데이터 유형이 지원됩니다:

고려 사항

  • 오브젝트 배열은 API를 통해 전송되는 커스텀 속성을 위한 것입니다. CSV 업로드는 지원되지 않습니다. CSV 파일의 쉼표가 열 구분자로 해석되고, 값 내의 쉼표가 파싱 오류를 일으키기 때문입니다.
  • 오브젝트 배열은 항목 수에 제한이 없지만 최대 크기는 100 KB입니다. 업데이트($add 또는 $update 등)로 인해 배열이 이 제한을 초과하면 Braze는 업데이트를 삭제하고 속성은 변경되지 않습니다. API 요청은 여전히 성공 응답을 반환합니다. 새 항목을 추가할 수 있도록 배열을 제한 이하로 유지하려면 먼저 $remove를 사용하여 배열에서 항목을 삭제하세요.
  • 모든 Braze 파트너가 오브젝트 배열을 지원하는 것은 아닙니다. 통합이 이 기능을 지원하는지 확인하려면 파트너 설명서를 참조하세요.

배열의 항목을 업데이트하거나 제거하려면 키와 값으로 항목을 식별해야 하므로, 배열의 각 항목에 고유 식별자를 포함하는 것을 고려하세요. 고유성은 해당 배열 내에서만 적용되며, 배열에서 특정 오브젝트를 업데이트하거나 제거하려는 경우에 유용합니다. 이는 Braze에서 강제하지 않습니다.

API 예시

다음은 pets 배열이 포함된 /users/track 예시입니다. 반려동물의 등록정보를 캡처하려면 pets를 오브젝트 배열로 나열하는 API 요청을 보내세요. 각 오브젝트에는 나중에 업데이트할 때 참조할 수 있는 고유한 id가 할당되어 있습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
  "attributes": [
    {
      "external_id": "user_id",
      "pets": [
        {
          "id": 1,
          "type": "dog",
          "breed": "beagle",
          "name": "Gus"
        },
        {
          "id": 2,
          "type": "cat",
          "breed": "calico",
          "name": "Gerald"
        }
      ]
    }
  ]
}

$add 연산자를 사용하여 배열에 다른 항목을 추가합니다. 다음 예시는 사용자의 pets 배열에 세 개의 반려동물 오브젝트를 추가하는 방법을 보여줍니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
  "attributes": [
    {
      "external_id": "user_id",
      "pets": {
        "$add": [
          {
            "id": 3,
            "type": "dog",
            "breed": "corgi",
            "name": "Doug"
          },
          {
            "id": 4,
            "type": "fish",
            "breed": "salmon",
            "name": "Larry"
          },
           {
            "id": 5,
            "type": "bird",
            "breed": "parakeet",
            "name": "Mary"
          }
        ]
      }
    }
  ]
}

_merge_objects 매개변수와 $update 연산자를 사용하여 배열 내 특정 오브젝트의 값을 업데이트합니다. 단순 중첩 고객 속성 오브젝트에 대한 업데이트와 유사하게, 이는 딥 머지를 수행합니다.

$update는 배열 내 오브젝트에서 중첩 등록정보를 제거하는 데 사용할 수 없습니다. 이를 수행하려면 배열에서 전체 항목을 제거한 다음 해당 특정 키 없이 오브젝트를 추가해야 합니다($remove$add의 조합 사용).

다음 예시는 id4인 오브젝트의 breed 등록정보를 goldfish로 업데이트하는 방법을 보여줍니다. 이 요청 예시는 또한 id5인 오브젝트의 nameAnnette로 업데이트합니다. _merge_objects 매개변수가 true로 설정되어 있으므로, 이 두 오브젝트의 다른 모든 필드는 동일하게 유지됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "attributes": [
    {
      "external_id": "user_id",
      "_merge_objects": true,
      "pets": {
        "$update": [
          {
            "$identifier_key": "id",
            "$identifier_value": 4,
            "$new_object": {
              "breed": "goldfish"
            }
          },
          {
            "$identifier_key": "id",
            "$identifier_value": 5,
            "$new_object": {
              "name": "Annette"
            }
          }
        ]
      }
    }
  ]
}

$remove 연산자를 일치하는 키($identifier_key)와 값($identifier_value)과 함께 사용하여 배열에서 오브젝트를 제거합니다.

다음 예시는 pets 배열에서 id 값이 1인 오브젝트, id 값이 2인 오브젝트, type 값이 dog인 오브젝트를 제거하는 방법을 보여줍니다. type 값이 dog인 오브젝트가 여러 개 있는 경우, 일치하는 모든 오브젝트가 제거됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "attributes": [
    {
      "external_id": "user_id",
      "pets": {
        "$remove": [
          // Remove by ID
          {
            "$identifier_key": "id",
            "$identifier_value": 1
          },
          {
            "$identifier_key": "id",
            "$identifier_value": 2
          },
          // Remove any dog
          {
            "$identifier_key": "type",
            "$identifier_value": "dog"
          }
        ]
      }
    }
  ]
}

처리 순서

단일 /users/track 요청에 동일한 배열 속성에 대한 $add, $remove, $update 작업이 포함된 경우, Braze는 다음 순서로 처리합니다:

  1. $add
  2. $remove
  3. $update

$add$remove보다 먼저 실행되므로, 단일 요청 내에서 $remove$add를 업서트 메커니즘으로 사용할 수 없습니다. $add가 먼저 처리된 다음 $remove가 항목을 삭제합니다. 업서트를 수행하려면 $add 전에 별도의 요청으로 $remove를 보내세요.

타임스탬프

오브젝트 배열에 타임스탬프와 같은 필드를 포함할 때는 일반 문자열이나 Unix 에포크 정수 대신 $time 형식을 사용하세요.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
  "attributes": [
    {
      "external_id": "user123",
      "purchases": [
        {
          "item_name": "T-shirt",
          "price": 19.99,
          "purchase_time": {
            "$time": "2020-05-28"
          }
        }
      ]
    }
  ]
}

SDK 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
val json = JSONArray()
    .put(JSONObject()
        .put("id", 1)
        .put("type", "dog")
        .put("breed", "beagle")
        .put("name", "Gus"))
    .put(JSONObject()
        .put("id", 2)
        .put("type", "cat")
        .put("breed", "calico")
        .put("name", "Gerald")
    )

braze.getCurrentUser { user ->
    user.setCustomUserAttribute("pets", json)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
val json = JSONObject()
    .put("\$add", JSONArray()
        .put(JSONObject()
            .put("id", 3)
            .put("type", "dog")
            .put("breed", "corgi")
            .put("name", "Doug"))
        .put(JSONObject()
            .put("id", 4)
            .put("type", "fish")
            .put("breed", "salmon")
            .put("name", "Larry"))
        .put(JSONObject()
            .put("id", 5)
            .put("type", "bird")
            .put("breed", "parakeet")
            .put("name", "Mary")
        )
    )

braze.getCurrentUser { user ->
    user.setCustomUserAttribute("pets", json, true)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
val json = JSONObject()
    .put("\$update", JSONArray()
        .put(JSONObject()
            .put("\$identifier_key", "id")
            .put("\$identifier_value", 4)
            .put("\$new_object", JSONObject()
                .put("breed", "goldfish")
            )
        )
        .put(JSONObject()
            .put("\$identifier_key", "id")
            .put("\$identifier_value", 5)
            .put("\$new_object", JSONObject()
                .put("name", "Annette")
            )
        )
    )

braze.getCurrentUser { user ->
    user.setCustomUserAttribute("pets", json, true)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
val json = JSONObject()
    .put("\$remove", JSONArray()
        .put(JSONObject()
            .put("\$identifier_key", "id")
            .put("\$identifier_value", 1)
        )
        .put(JSONObject()
            .put("\$identifier_key", "id")
            .put("\$identifier_value", 2)
        )
        .put(JSONObject()
            .put("\$identifier_key", "type")
            .put("\$identifier_value", "dog")
        )
    )

braze.getCurrentUser { user ->
    user.setCustomUserAttribute("pets", json, true)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let json: [[String: Any?]] = [
  [
    "id": 1,
    "type": "dog",
    "breed": "beagle",
    "name": "Gus"
  ],
  [
    "id": 2,
    "type": "cat",
    "breed": "calico",
    "name": "Gerald"
  ]
]

braze.user.setCustomAttribute(key: "pets", array: json)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let json: [String: Any?] = [
  "$add": [
    [
      "id": 3,
      "type": "dog",
      "breed": "corgi",
      "name": "Doug"
    ],
    [
      "id": 4,
      "type": "fish",
      "breed": "salmon",
      "name": "Larry"
    ],
    [
      "id": 5,
      "type": "bird",
      "breed": "parakeet",
      "name": "Mary"
    ]
  ]
]

braze.user.setCustomAttribute(key: "pets", dictionary: json, merge: true)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let json: [String: Any?] = [
  "$update": [
    [
      "$identifier_key": "id",
      "$identifier_value": 4,
      "$new_object": [
        "breed": "goldfish"
      ]
    ],
    [
      "$identifier_key": "id",
      "$identifier_value": 5,
      "$new_object": [
        "name": "Annette"
      ]
    ]
  ]
]

braze.user.setCustomAttribute(key: "pets", dictionary: json, merge: true)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
let json: [String: Any?] = [
  "$remove": [
    [
      "$identifier_key": "id",
      "$identifier_value": 1,
    ],
    [
      "$identifier_key": "id",
      "$identifier_value": 2,
    ],
    [
      "$identifier_key": "type",
      "$identifier_value": "dog",
    ]
  ]
]

braze.user.setCustomAttribute(key: "pets", dictionary: json, merge: true)
1
2
3
4
5
6
7
8
9
10
11
12
13
import * as braze from "@braze/web-sdk";
const json = [{
  "id": 1,
  "type": "dog",
  "breed": "beagle",
  "name": "Gus"
}, {
  "id": 2,
  "type": "cat",
  "breed": "calico",
  "name": "Gerald"
}];
braze.getUser().setCustomUserAttribute("pets", json);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import * as braze from "@braze/web-sdk";
const json = {
  "$add": [{
    "id":  3,
    "type":  "dog",
    "breed":  "corgi",
    "name":  "Doug",
  }, {
    "id":  4,
    "type":  "fish",
    "breed":  "salmon",
    "name":  "Larry",
  }, {
    "id":  5,
    "type":  "bird",
    "breed":  "parakeet",
    "name":  "Mary",
  }]
};
braze.getUser().setCustomUserAttribute("pets", json, true);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import * as braze from "@braze/web-sdk";
const json = {
  "$update": [
    {
      "$identifier_key": "id",
      "$identifier_value": 4,
      "$new_object": {
        "breed": "goldfish"
      }
    },
    {
      "$identifier_key": "id",
      "$identifier_value": 5,
      "$new_object": {
        "name": "Annette"
      }
    }
  ]
};
braze.getUser().setCustomUserAttribute("pets", json, true);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import * as braze from "@braze/web-sdk";
const json = {
  "$remove": [
    {
      "$identifier_key": "id",
      "$identifier_value": 1,
    },
    {
      "$identifier_key": "id",
      "$identifier_value": 2,
    },
    {
      "$identifier_key": "type",
      "$identifier_value": "dog",
    }
  ]
};
braze.getUser().setCustomUserAttribute("pets", json, true);

Liquid 템플릿

pets 배열을 사용하여 메시지를 개인화할 수 있습니다. 다음 Liquid 템플릿 예시는 앞선 API 요청에서 저장된 커스텀 속성 오브젝트 등록정보를 참조하고 메시징에 사용하는 방법을 보여줍니다.

1
2
3
4
5
{% assign pets = {{custom_attribute.${pets}}} %} 
 
{% for pet in pets %}
I have a {{pet.type}} named {{pet.name}}! They are a {{pet.breed}}.
{% endfor %} 

이 시나리오에서는 Liquid를 사용하여 pets 배열을 반복하고 각 반려동물에 대한 문장을 출력할 수 있습니다. pets 커스텀 속성에 변수를 할당하고 점 표기법을 사용하여 오브젝트의 등록정보에 접근합니다. 오브젝트 이름 뒤에 마침표 .를 입력하고, 그 뒤에 등록정보 이름을 지정합니다.

세분화

오브젝트 배열을 기반으로 사용자를 세분화할 때, 배열의 오브젝트 중 하나라도 기준과 일치하면 해당 사용자는 세그먼트에 포함됩니다.

새 세그먼트를 생성하고 필터로 중첩 고객 속성을 선택합니다. 그런 다음 오브젝트 배열의 이름을 검색하고 선택합니다.

오브젝트 배열로 필터링.

점 표기법을 사용하여 오브젝트 배열에서 사용할 필드를 지정합니다. 텍스트 필드를 빈 대괄호 []로 시작하여 Braze에 오브젝트 배열 내부를 조회하고 있음을 알립니다. 그 뒤에 마침표 .를 추가하고, 사용할 필드 이름을 입력합니다.

예를 들어, type 필드를 기반으로 top_3_movies 오브젝트 배열을 필터링하려면 [].type을 입력하고 Fantasy Movie와 같이 필터링할 영화를 선택합니다.

중첩 수준

최대 한 수준의 배열 중첩(배열 내의 배열)으로 세그먼트를 생성할 수 있습니다. 예를 들어, 다음 속성이 주어진 경우 pets[].nameGus가 포함된 세그먼트는 만들 수 있지만, pets[].nicknames[]Gugu가 포함된 세그먼트는 만들 수 없습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
  "attributes": [
    {
      "external_id": "user_id",
      "pets": [
        {
          "id": 1,
          "type": "dog",
          "breed": "beagle",
          "name": "Gus",
          "nicknames": [
            "Gugu",
            "Gusto"
          ]
        },
        {
          "id": 2,
          "type": "cat",
          "breed": "calico",
          "name": "Gerald",
          "nicknames": [
            "GeGe",
            "Gerry"
          ]
        }
      ]
    }
  ]
}

데이터 포인트

데이터 포인트는 등록정보를 생성, 업데이트 또는 제거하는지에 따라 다르게 기록됩니다.

새 배열을 생성하면 오브젝트의 각 속성에 대해 하나의 데이터 포인트가 기록됩니다. 이 예시는 8개의 데이터 포인트가 소비됩니다. 각 반려동물 오브젝트에는 4개의 속성이 있고 오브젝트가 2개 있기 때문입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
  "attributes": [
    {
      "external_id": "user_id",
      "pets": [
        {
          "id": 1,
          "type": "dog",
          "breed": "beagle",
          "name": "Gus"
        },
        {
          "id": 2,
          "type": "cat",
          "breed": "calico",
          "name": "Gerald"
        }
      ]
    }
  ]
}

기존 배열을 업데이트하면 추가된 각 등록정보에 대해 하나의 데이터 포인트가 기록됩니다. 이 예시는 두 개의 오브젝트 각각에서 하나의 등록정보만 업데이트하므로 2개의 데이터 포인트가 소비됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "attributes": [
    {
      "external_id": "user_id",
      "_merge_objects": true,
      "pets": {
        "$update": [
          {
            "$identifier_key": "id",
            "$identifier_value": 4,
            "$new_object": {
              "breed": "goldfish"
            }
          },
          {
            "$identifier_key": "id",
            "$identifier_value": 5,
            "$new_object": {
              "name": "Annette"
            }
          }
        ]
      }
    }
  ]
}

배열에서 오브젝트를 제거하면 전송하는 각 제거 기준에 대해 하나의 데이터 포인트가 기록됩니다. 이 예시는 이 구문으로 여러 마리의 개를 제거할 수 있더라도 3개의 데이터 포인트가 소비됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "attributes": [
    {
      "external_id": "user_id",
      "pets": {
        "$remove": [
          // Remove by ID
          {
            "$identifier_key": "id",
            "$identifier_value": 1
          },
          {
            "$identifier_key": "id",
            "$identifier_value": 2
          },
          // Remove any dog
          {
            "$identifier_key": "type",
            "$identifier_value": "dog"
          }
        ]
      }
    }
  ]
}
New Stuff!