Skip to content

Commit f491be5

Browse files
committed
updated readme
1 parent 83f7330 commit f491be5

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

CHANGELOG.md

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

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

5-
* Add support for passing callback functions to logEvent
7+
* Add support for passing callback functions to logEvent.
68

79
## 2.3.0 (September 2, 2015)
810

@@ -11,7 +13,7 @@
1113
## 2.2.1 (Aug 13, 2015)
1214

1315
* Fix bug where multi-byte unicode characters were hashed improperly.
14-
* Add option to sent referrer information as user properties
16+
* Add option to send referrer information as user properties.
1517

1618
## 2.2.0 (May 5, 2015)
1719

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('city', 'Boston, MA').set('country', 'United States');
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, the city will be set once to `Boston, MA`, and the following setOnce to `San Francisco, CA` will be ignored:
71+
72+
```javascript
73+
var identify = new amplitude.Identify().setOnce('city', 'Boston, MA');
74+
amplitude.identify(identify);
75+
76+
var identify = new amplitude.Identify().setOnce('city', 'San Francisco, CA');
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('city').unset('country');
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

src/amplitude.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,13 @@ Amplitude.prototype.setDeviceId = function(deviceId) {
321321
};
322322

323323
Amplitude.prototype.setUserProperties = function(userProperties) {
324-
325324
// convert userProperties into an identify call
326325
var identify = new Identify();
327326
for (var property in userProperties) {
328327
if (userProperties.hasOwnProperty(property)) {
329328
identify.set(property, userProperties[property]);
330329
}
331330
}
332-
333-
// _saveCookieData(this); ??
334331
this.identify(identify);
335332
};
336333

0 commit comments

Comments
 (0)