Skip to main content

Hi! I was trying to add user properties to an event and I tried doing the following: 

var userProperties = {
city: "San Francisco"
};
// @ts-ignore
var amp = amplitude.getInstance();
amp.logEvent(eventName);
amp.setUserProperties(userProperties);

However, this event tracked twice: as a “Continue button clicked” event without user properties and also as a $identify event with user properties. Is there a specific way I should be configuring the user properties to add them to the specific event, rather than tracking as a separate $identify event? Thanks in advance!

Hi @carissa.mok ! Welcome to the Amplitude Community and I’m happy to help! :wave_tone1:

Given the example you provided, it seems like you are using one of our SDKs. If so, user properties are actually sent within an $identify call so the behavior you are seeing is expected. So long as the user properties are set before the event call, the event call will pick up the user properties listed in the $identify call. When you look up this event in Amplitude, you should see that the user properties are actually on the event itself. 

Only events sent via server-side will you be able to include the user properties specifically with the event call: https://help.amplitude.com/hc/en-us/articles/115002380567#applying-user-properties-to-events

Feel free to read more of the Help Center article I just linked to understand how user properties work! 


Hi Belinda, thanks for the response! I have a few more questions that I’m hoping you’ll be able to help me out with: 

  1. Does it matter where I set user properties? It seems that even if I do it in the same file as one particular event, the same user properties will show up for other tracked events of different types.
  2. I deleted a user property in the Govern tab but it’s still showing up when I click into a specific event — any way to hide this? 

Thanks for your help!


Sure @carissa.mok ! Happy to do so - see below: 

  1. User properties are attributes of the user so once it shows up on a user’s profile, then it will show up for all events moving forward! As such, it theoretically doesn’t matter where you set the user properties but do keep in mind again about how user properties behave if you sent it before OR after the events. I recommend reading this article I shared last time: https://help.amplitude.com/hc/en-us/articles/115002380567#applying-user-properties-to-events 
  2. To clarify, do you mean you still see the user property appear when you see an event within a user’s profile? Or do you mean when you click on the user property dropdown in charts, you still see the user property? A screenshot of where you are referring to would be helpful! 

Thanks for clearing up the nature of user properties. 

I mean when I click into a specific event (to see the user profile I think), the property still shows up. In the screenshot below, I’ve been trying to delete/hide the city property that I created just as a tester.

 


@carissa.mok Got it! Thanks for sharing that. So this is expected behavior. Deleting a user property will prevent that user property from ingesting moving forward and also remove that user property from being selectable on chart drop downs moving forward. But deleting a user property does not delete historical data hence you will still see the user property on events and user profiles. That said you could remove the user property from appearing on the top half of the user profile (the section you screenshotted) if you unset the user property.   


@belinda.chiu Could you clarify what you mean by unsetting the user property in order to remove the property from appearing in the user profile?


@carissa.mok Sure! There are many different kinds of user property operations and of one is simply an unset operation which will allow you to unset and remove the value of the property. 

Not too sure how you are instrumenting data to Amplitude but let’s use this set operation for example https://developers.amplitude.com/docs/javascript#set. Instead of writing

var identify1 = new amplitude.Identify().set('key1', 'value1');

you will effectively do 

var identify1 = new amplitude.Identify().unset('key1', 'value1');

Other examples: 

https://developers.amplitude.com/docs/android#unset
https://developers.amplitude.com/docs/identify-api#:~:text=%24unset%20(remove%20a%20property)

 


@belinda.chiu So I used

setUserProperties()

 so would it be the same type of pattern with

unsetUserProperties()

?


@carissa.mok Ah I see! The setUserProperties is just a wrapper around the set. We do not have a convenience wrapper like unsetUserProperties(<list of strings>) or something that the SDK internally builds an identify call for you, similar to what setUserProperties does. 

For unsetting, you will have to call an unset operation via identify. 


Reply