Skip to content

Commit 83b6d66

Browse files
committed
Merge pull request #61 from amplitude/revert-60-set_group
Revert "Set group"
2 parents 8b6ab05 + af0f9e9 commit 83b6d66

File tree

6 files changed

+12
-157
lines changed

6 files changed

+12
-157
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
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.
76

87
### 2.9.1 (March 6, 2016)
98

README.md

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

243-
### Setting Groups ###
244-
245-
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.
246-
247-
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.
248-
249-
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, as well as the corresponding user property value.** 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.
250-
251-
```javascript
252-
amplitude.setGroup('orgId', 15);
253-
amplitude.setGroup('sport', 'tennis');
254-
```
255-
256-
You can also use `logEventWithGroups` to set event-level groups, meaning the group designation only applies for the specific event being logged and does not persist on the user unless you explicitly set it with `setGroup`.
257-
258-
```javascript
259-
var eventProperties = {
260-
'key': 'value'
261-
}
262-
263-
amplitude.logEventWithGroups('initialize_game', eventProperties, {'sport': 'soccer'});
264-
```
265-
266243
### Setting Version Name ###
267244
By default, no version name is set. You can specify a version name to distinguish between different versions of your site by calling `setVersionName`:
268245

amplitude.js

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

548-
Amplitude.prototype.setGroup = function(groupType, groupName) {
549-
if (!this._apiKeySet('setGroup()')) {
550-
return;
551-
}
552-
553-
var groups = {};
554-
groups[groupType] = groupName;
555-
556-
var identify = new Identify().set(groupType, groupName);
557-
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null);
558-
};
559-
560548
Amplitude.prototype.setOptOut = function(enable) {
561549
if (!this._apiKeySet('setOptOut()')) {
562550
return;
@@ -632,7 +620,7 @@ Amplitude.prototype.identify = function(identify, callback) {
632620
}
633621

634622
if (identify instanceof Identify && Object.keys(identify.userPropertiesOperations).length > 0) {
635-
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, null, callback);
623+
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, callback);
636624
} else if (callback && type(callback) === 'function') {
637625
callback(0, 'No request sent');
638626
}
@@ -676,7 +664,7 @@ var _truncateValue = function(value) {
676664
/**
677665
* Private logEvent method. Keeps apiProperties from being publicly exposed.
678666
*/
679-
Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperties, userProperties, groups, callback) {
667+
Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperties, userProperties, callback) {
680668
if (type(callback) !== 'function') {
681669
callback = null;
682670
}
@@ -712,7 +700,6 @@ Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperti
712700

713701
apiProperties = apiProperties || {};
714702
eventProperties = eventProperties || {};
715-
groups = groups || {};
716703
var event = {
717704
device_id: this.options.deviceId,
718705
user_id: this.options.userId || this.options.deviceId,
@@ -734,8 +721,7 @@ Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperti
734721
name: 'amplitude-js',
735722
version: version
736723
},
737-
sequence_number: sequenceNumber, // for ordering events and identifys
738-
groups: this._truncate(utils.validateProperties(groups))
724+
sequence_number: sequenceNumber // for ordering events and identifys
739725
// country: null
740726
};
741727

@@ -776,17 +762,7 @@ Amplitude.prototype.logEvent = function(eventType, eventProperties, callback) {
776762
}
777763
return -1;
778764
}
779-
return this._logEvent(eventType, eventProperties, null, null, null, callback);
780-
};
781-
782-
Amplitude.prototype.logEventWithGroups = function(eventType, eventProperties, groups, callback) {
783-
if (!this._apiKeySet('logEventWithGroup()')) {
784-
if (callback && type(callback) === 'function') {
785-
callback(0, 'No request sent');
786-
}
787-
return -1;
788-
}
789-
return this._logEvent(eventType, eventProperties, null, null, groups, callback);
765+
return this._logEvent(eventType, eventProperties, null, null, callback);
790766
};
791767

792768
// Test that n is a number or a numeric value.
@@ -806,7 +782,7 @@ Amplitude.prototype.logRevenue = function(price, quantity, product) {
806782
special: 'revenue_amount',
807783
quantity: quantity || 1,
808784
price: price
809-
}, null, null, null);
785+
});
810786
};
811787

812788
/**

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude.js

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

442-
Amplitude.prototype.setGroup = function(groupType, groupName) {
443-
if (!this._apiKeySet('setGroup()')) {
444-
return;
445-
}
446-
447-
var groups = {};
448-
groups[groupType] = groupName;
449-
450-
var identify = new Identify().set(groupType, groupName);
451-
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null);
452-
};
453-
454442
Amplitude.prototype.setOptOut = function(enable) {
455443
if (!this._apiKeySet('setOptOut()')) {
456444
return;
@@ -526,7 +514,7 @@ Amplitude.prototype.identify = function(identify, callback) {
526514
}
527515

528516
if (identify instanceof Identify && Object.keys(identify.userPropertiesOperations).length > 0) {
529-
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, null, callback);
517+
this._logEvent(IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, callback);
530518
} else if (callback && type(callback) === 'function') {
531519
callback(0, 'No request sent');
532520
}
@@ -570,7 +558,7 @@ var _truncateValue = function(value) {
570558
/**
571559
* Private logEvent method. Keeps apiProperties from being publicly exposed.
572560
*/
573-
Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperties, userProperties, groups, callback) {
561+
Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperties, userProperties, callback) {
574562
if (type(callback) !== 'function') {
575563
callback = null;
576564
}
@@ -606,7 +594,6 @@ Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperti
606594

607595
apiProperties = apiProperties || {};
608596
eventProperties = eventProperties || {};
609-
groups = groups || {};
610597
var event = {
611598
device_id: this.options.deviceId,
612599
user_id: this.options.userId || this.options.deviceId,
@@ -628,8 +615,7 @@ Amplitude.prototype._logEvent = function(eventType, eventProperties, apiProperti
628615
name: 'amplitude-js',
629616
version: version
630617
},
631-
sequence_number: sequenceNumber, // for ordering events and identifys
632-
groups: this._truncate(utils.validateProperties(groups))
618+
sequence_number: sequenceNumber // for ordering events and identifys
633619
// country: null
634620
};
635621

@@ -670,17 +656,7 @@ Amplitude.prototype.logEvent = function(eventType, eventProperties, callback) {
670656
}
671657
return -1;
672658
}
673-
return this._logEvent(eventType, eventProperties, null, null, null, callback);
674-
};
675-
676-
Amplitude.prototype.logEventWithGroups = function(eventType, eventProperties, groups, callback) {
677-
if (!this._apiKeySet('logEventWithGroup()')) {
678-
if (callback && type(callback) === 'function') {
679-
callback(0, 'No request sent');
680-
}
681-
return -1;
682-
}
683-
return this._logEvent(eventType, eventProperties, null, null, groups, callback);
659+
return this._logEvent(eventType, eventProperties, null, null, callback);
684660
};
685661

686662
// Test that n is a number or a numeric value.
@@ -700,7 +676,7 @@ Amplitude.prototype.logRevenue = function(price, quantity, product) {
700676
special: 'revenue_amount',
701677
quantity: quantity || 1,
702678
price: price
703-
}, null, null, null);
679+
});
704680
};
705681

706682
/**

test/amplitude.js

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -534,36 +534,6 @@ describe('Amplitude', function() {
534534
});
535535
});
536536

537-
describe('setGroup', function() {
538-
539-
beforeEach(function() {
540-
reset();
541-
amplitude.init(apiKey);
542-
});
543-
544-
afterEach(function() {
545-
reset();
546-
});
547-
548-
it('should generate an identify event with groups set', function() {
549-
amplitude.setGroup('orgId', 15);
550-
assert.lengthOf(server.requests, 1);
551-
var events = JSON.parse(querystring.parse(server.requests[0].requestBody).e);
552-
assert.lengthOf(events, 1);
553-
554-
// verify identify event
555-
var identify = events[0];
556-
assert.equal(identify.event_type, '$identify');
557-
assert.deepEqual(identify.user_properties, {
558-
'$set': {'orgId': 15},
559-
});
560-
assert.deepEqual(identify.event_properties, {});
561-
assert.deepEqual(identify.groups, {
562-
'orgId': 15,
563-
});
564-
});
565-
});
566-
567537
describe('setDeviceId', function() {
568538

569539
beforeEach(function() {
@@ -1676,49 +1646,6 @@ describe('Amplitude', function() {
16761646
assert.equal(amplitude2._unsentIdentifys[0]['sequence_number'], sequenceNumber + 4);
16771647
assert.equal(amplitude1._unsentEvents[2]['sequence_number'], sequenceNumber + 5);
16781648
});
1679-
1680-
it('should handle groups input', function() {
1681-
var counter = 0;
1682-
var value = -1;
1683-
var message = '';
1684-
var callback = function (status, response) {
1685-
counter++;
1686-
value = status;
1687-
message = response;
1688-
};
1689-
1690-
var eventProperties = {
1691-
'key': 'value'
1692-
};
1693-
1694-
var groups = {
1695-
'group1': 'value1',
1696-
'group2': 'value2',
1697-
}
1698-
1699-
amplitude.logEventWithGroups('Test', eventProperties, groups, callback);
1700-
assert.lengthOf(server.requests, 1);
1701-
var events = JSON.parse(querystring.parse(server.requests[0].requestBody).e);
1702-
assert.lengthOf(events, 1);
1703-
1704-
// verify event is correctly formatted
1705-
var event = events[0];
1706-
assert.equal(event.event_type, 'Test');
1707-
assert.equal(event.event_id, 1);
1708-
assert.deepEqual(event.user_properties, {});
1709-
assert.deepEqual(event.event_properties, eventProperties);
1710-
assert.deepEqual(event.groups, groups);
1711-
1712-
// verify callback behavior
1713-
assert.equal(counter, 0);
1714-
assert.equal(value, -1);
1715-
assert.equal(message, '');
1716-
server.respondWith('success');
1717-
server.respond();
1718-
assert.equal(counter, 1);
1719-
assert.equal(value, 200);
1720-
assert.equal(message, 'success');
1721-
});
17221649
});
17231650

17241651
describe('optOut', function() {

0 commit comments

Comments
 (0)