Skip to content

Commit 6a15744

Browse files
committed
Merge pull request #26 from amplitude/user_properties_operations
Add support for user property operations
2 parents d024adc + b479c60 commit 6a15744

File tree

11 files changed

+1370
-230
lines changed

11 files changed

+1370
-230
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
* Add support for user properties operations (set, setOnce, add, unset).
4+
35
## 2.4.1 (September 21, 2015)
46

57
* Add support for passing callback function to init.
@@ -8,7 +10,7 @@
810

911
## 2.4.0 (September 4, 2015)
1012

11-
* Add support for passing callback functions to logEvent
13+
* Add support for passing callback functions to logEvent.
1214

1315
## 2.3.0 (September 2, 2015)
1416

@@ -17,7 +19,7 @@
1719
## 2.2.1 (Aug 13, 2015)
1820

1921
* Fix bug where multi-byte unicode characters were hashed improperly.
20-
* Add option to sent referrer information as user properties
22+
* Add option to send referrer information as user properties.
2123

2224
## 2.2.0 (May 5, 2015)
2325

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,48 @@ To add properties that are tracked in every event, you can set properties for a
5656
userProperties.key = "value";
5757
amplitude.setUserProperties(userProperties);
5858

59+
# User Property Operations #
60+
61+
The SDK supports the operations set, setOnce, unset, and add on individual user properties. The operations are declared via a provided `Identify` interface. Multiple operations can be chained together in a single `Identify` object. The `Identify` object is then passed to the Amplitude client to send to the server. The results of the operations will be visible immediately in the dashboard, and take effect for events logged after.
62+
63+
1. `set`: this sets the value of a user property.
64+
65+
```javascript
66+
var identify = new amplitude.Identify().set('gender', 'female').set('age', 20);
67+
amplitude.identify(identify);
68+
```
69+
70+
2. `setOnce`: this sets the value of a user property only once. Subsequent `setOnce` operations on that user property will be ignored. In the following example, `sign_up_date` will be set once to `08/24/2015`, and the following setOnce to `09/14/2015` will be ignored:
71+
72+
```javascript
73+
var identify = new amplitude.Identify().setOnce('sign_up_date', '08/24/2015');
74+
amplitude.identify(identify);
75+
76+
var identify = new amplitude.Identify().setOnce('sign_up_date', '09/14/2015');
77+
amplitude.identify(identify);
78+
```
79+
80+
3. `unset`: this will unset and remove a user property.
81+
82+
```javascript
83+
var identify = new amplitude.Identify().unset('gender').unset('age');
84+
amplitude.identify(identify);
85+
```
86+
87+
4. `add`: this will increment a user property by some numerical value. If the user property does not have a value set yet, it will be initialized to 0 before being incremented.
88+
89+
```javascript
90+
var identify = new amplitude.Identify().add('karma', 1).add('friends', 1);
91+
amplitude.identify(identify);
92+
```
93+
94+
Note: if a user property is used in multiple operations on the same `Identify` object, only the first operation will be saved, and the rest will be ignored. In this example, only the set operation will be saved, and the add and unset will be ignored:
95+
96+
```javascript
97+
var identify = new amplitude.Identify().set('karma', 10).add('karma', 1).unset('karma');
98+
amplitude.identify(identify);
99+
```
100+
59101
# Tracking Revenue #
60102

61103
To track revenue from a user, call

0 commit comments

Comments
 (0)