Google Tag Manager

Forum Discussion

David_M's avatar
David_M
Influencer
4 hours ago

Segment Source Function to Braze

I have been using Javascript to send simple event and attribute information to braze. 

Sometimes i have had to change the outputs but using a dictionary/library but generally still sending simple string Events (event properties) and custom_attributes 

However today I'm trying to send an account_opened event 

Event: account_opened
Event Properties: account_number, account_type (values lets say account_a, account_b

Event and properties are all firing fine. 

But i also want to update an Array with account_types_held and account_numbers_held 

the future user case for this is so we don't have to keep getting a CSV list for people that hold a certain account type when we perhaps do maintenance on those account types. 

it's populating the attributes each time but overwriting the old one rather than appending in a list - i believe this is because Braze is not receiving the $add 

So how should this Javascript be set up? 

I think it should be instead of using the identify call the direct: 

// Call Braze API directly to append to array attributes const response = await fetch(`${settings.brazeEndpoint}/users/track`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${settings.brazeApiKey}` },

Any advice?

Webhook > segment > braze via source functions 


1 Reply

  • https://www.braze.com/docs/user_guide/data/activation/custom_data/custom_attributes/array_of_objects/#limitations

    Updating or removing items in an array requires identifying the item by key and value, so consider including a unique identifier for each item in the array. The uniqueness is scoped only to the array and is useful if you want to update and remove specific objects from your array. This is not enforced by Braze.

    For update (there is also an example on the page for add):

    https://www.braze.com/docs/user_guide/data/activation/custom_data/custom_attributes/array_of_objects/?tab=update#api-example

    { "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" } } ] } } ] }