Skip to content

Commit e9ed4c0

Browse files
committed
update changelog and readme
1 parent 97bf133 commit e9ed4c0

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Add support for passing callback function to identify.
44
* Add support for prepend user property operation.
55
* Keep sessions and event metadata in sync across multiple windows/tabs.
6+
* Add support for setting groups for users and events.
67

78
### 2.9.1 (March 6, 2016)
89

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,29 @@ amplitude.init('YOUR_API_KEY_HERE', null, {
229229
# Advanced #
230230
This SDK automatically grabs useful data about the browser, including browser type and operating system version.
231231

232+
### Setting Groups ###
233+
234+
Amplitude supports assigning users to groups, and performing queries such as count by distinct on those groups. An example would be if you want to group your users based on what organization they are in (based on something like an orgId). For example you can designate user Joe to be in orgId 10, while Sue is in orgId 15. When performing an event segmentation query, you can then select Count By: orgId, to query the number of different orgIds that have performed a specific event. As long as at least one member of that group has performed the specific event, that group will be included in the count. See our help article on [Count By Distinct]() for more information.
235+
236+
In the above example, 'orgId' is a `groupType`, and the value 10 or 15 is the `groupName`. Another example of a `groupType` could a sport that the user participates in, and possible `groupNames` within that type would be tennis, baseball, etc.
237+
238+
You can use `setGroup(groupType, groupName)` to designate which groups a user belongs to. Few things to note: this will also set the `groupType: groupName` as a user property. This will overwrite any existing groupName value set for that user's groupType. For example if Joe was in orgId 10, and you call `setGroup('orgId', 20)`, 20 would replace 10. You can also call `setGroup` multiple times with different groupTypes to add a user to different groups. For example Sue is in orgId: 15, and she also plays sport: soccer. Now when querying, you can Count By both orgId and sport. You are allowed to set up to 5 different groupTypes per user. Any more than that will be ignored from the query UI, although they will still appear as user properties.
239+
240+
```javascript
241+
amplitude.setGroup('orgId', 15);
242+
amplitude.setGroup('sport', 'tennis');
243+
```
244+
245+
You can also use `logEventWithGroups` to set event-level groups, meaning the group designation only applies for the specific event being logged.
246+
247+
```javascript
248+
var eventProperties = {
249+
'key': 'value'
250+
}
251+
252+
amplitude.logEventWithGroups('initialize_game', eventProperties, {'sport': 'soccer'});
253+
```
254+
232255
### Setting Version Name ###
233256
By default, no version name is set. You can specify a version name to distinguish between different versions of your site by calling `setVersionName`:
234257

amplitude.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,15 @@ Amplitude.prototype.setUserId = function(userId) {
545545
}
546546
};
547547

548-
Amplitude.prototype.setGroup = function(groupName, value) {
548+
Amplitude.prototype.setGroup = function(groupType, groupName) {
549549
if (!this._apiKeySet('setGroup()')) {
550550
return;
551551
}
552552

553553
var groups = {};
554-
groups[groupName] = value;
554+
groups[groupType] = groupName;
555555

556-
var identify = new Identify().set(groupName, value);
556+
var identify = new Identify().set(groupType, groupName);
557557
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null);
558558
};
559559

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,15 @@ Amplitude.prototype.setUserId = function(userId) {
439439
}
440440
};
441441

442-
Amplitude.prototype.setGroup = function(groupName, value) {
442+
Amplitude.prototype.setGroup = function(groupType, groupName) {
443443
if (!this._apiKeySet('setGroup()')) {
444444
return;
445445
}
446446

447447
var groups = {};
448-
groups[groupName] = value;
448+
groups[groupType] = groupName;
449449

450-
var identify = new Identify().set(groupName, value);
450+
var identify = new Identify().set(groupType, groupName);
451451
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null);
452452
};
453453

0 commit comments

Comments
 (0)