Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user properties convenience methods #9

Closed
wants to merge 2 commits into from
Closed

Conversation

jonyo
Copy link
Contributor

@jonyo jonyo commented Apr 29, 2016

This adds method addUserProperties() to event object, to easily add properties. It also changes the behavior of $amplitude->addUserProperties() to only add new properties, not change ones already set, so there are no surprises with the name addUserProperties...

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 92.353% when pulling 287d51a on event-add-user-props into 0d46d99 on master.

*
* @param array $userProperties
*/
public function addUserProperties(array $userProperties)
{
$this->userProperties = array_merge($this->userProperties, $userProperties);
$this->userProperties = $this->userProperties + $userProperties;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonyo Shouldn't be the other way round? This is ignoring keys that are previously defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrbasso I figured if you are calling a method named addUserProperties you would expect it to add any new properties and may be surprised if existing properties get overwritten. Otherwise mergeUserProperties() might be a better name...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonyo Hmmmm, silently ignoring data could be a problem too, even on purpose. Maybe the merge name fits better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I originally used addUserProperties() name to begin with: in Amplitude, you are always adding to or changing existing properties, you are never clearing old properties.

The above changes were because I figured, well, what I said above, the name implies it would not overwrite, just add new properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrbasso When in doubt, I guess look at how the official version works...

Looking at the JS SDK, they use setUserProperties(). I could change to use that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonyo Sounds good to me. Using the same name of other SDKs is also a good thing. 👍

@jonyo
Copy link
Contributor Author

jonyo commented Apr 29, 2016

Closing, going to use setUserProperties() instead.

@jonyo jonyo closed this Apr 29, 2016
@jonyo jonyo deleted the event-add-user-props branch April 29, 2016 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants