@@ -925,6 +925,7 @@ var constants = {
925
925
MAX_STRING_LENGTH : 4096 ,
926
926
MAX_PROPERTY_KEYS : 1000 ,
927
927
IDENTIFY_EVENT : '$identify' ,
928
+ GROUP_IDENTIFY_EVENT : '$groupidentify' ,
928
929
929
930
// localStorageKeys
930
931
LAST_EVENT_ID : 'amplitude_lastEventId' ,
@@ -3977,7 +3978,7 @@ var defineProperty = (function() {
3977
3978
} catch ( e ) { }
3978
3979
} ( ) ) ;
3979
3980
3980
- var _defineProperty = defineProperty ;
3981
+ var _defineProperty$1 = defineProperty ;
3981
3982
3982
3983
/**
3983
3984
* The base implementation of `assignValue` and `assignMergeValue` without
@@ -3989,8 +3990,8 @@ var _defineProperty = defineProperty;
3989
3990
* @param {* } value The value to assign.
3990
3991
*/
3991
3992
function baseAssignValue ( object , key , value ) {
3992
- if ( key == '__proto__' && _defineProperty ) {
3993
- _defineProperty ( object , key , {
3993
+ if ( key == '__proto__' && _defineProperty$1 ) {
3994
+ _defineProperty$1 ( object , key , {
3994
3995
'configurable' : true ,
3995
3996
'enumerable' : true ,
3996
3997
'value' : value ,
@@ -5167,8 +5168,8 @@ var constant_1 = constant;
5167
5168
* @param {Function } string The `toString` result.
5168
5169
* @returns {Function } Returns `func`.
5169
5170
*/
5170
- var baseSetToString = ! _defineProperty ? identity_1 : function ( func , string ) {
5171
- return _defineProperty ( func , 'toString' , {
5171
+ var baseSetToString = ! _defineProperty$1 ? identity_1 : function ( func , string ) {
5172
+ return _defineProperty$1 ( func , 'toString' , {
5172
5173
'configurable' : true ,
5173
5174
'enumerable' : false ,
5174
5175
'value' : constant_1 ( string ) ,
@@ -6665,6 +6666,8 @@ var DEFAULT_OPTIONS = {
6665
6666
uploadBatchSize : 100
6666
6667
} ;
6667
6668
6669
+ function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
6670
+
6668
6671
/**
6669
6672
* AmplitudeClient SDK API - instance constructor.
6670
6673
* The Amplitude class handles creation of client instances, all you need to do is call amplitude.getInstance()
@@ -7321,7 +7324,7 @@ AmplitudeClient.prototype.setGroup = function (groupType, groupName) {
7321
7324
var groups = { } ;
7322
7325
groups [ groupType ] = groupName ;
7323
7326
var identify = new Identify ( ) . set ( groupType , groupName ) ;
7324
- this . _logEvent ( constants . IDENTIFY_EVENT , null , null , identify . userPropertiesOperations , groups , null , null ) ;
7327
+ this . _logEvent ( constants . IDENTIFY_EVENT , null , null , identify . userPropertiesOperations , groups , null , null , null ) ;
7325
7328
} ;
7326
7329
7327
7330
/**
@@ -7479,7 +7482,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
7479
7482
if ( identify_obj instanceof Identify ) {
7480
7483
// only send if there are operations
7481
7484
if ( Object . keys ( identify_obj . userPropertiesOperations ) . length > 0 ) {
7482
- return this . _logEvent ( constants . IDENTIFY_EVENT , null , null , identify_obj . userPropertiesOperations , null , null , opt_callback ) ;
7485
+ return this . _logEvent ( constants . IDENTIFY_EVENT , null , null , identify_obj . userPropertiesOperations , null , null , null , opt_callback ) ;
7483
7486
} else {
7484
7487
if ( type ( opt_callback ) === 'function' ) {
7485
7488
opt_callback ( 0 , 'No request sent' , { reason : 'No user property operations' } ) ;
@@ -7493,6 +7496,50 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
7493
7496
}
7494
7497
} ;
7495
7498
7499
+ AmplitudeClient . prototype . groupIdentify = function ( group_type , group_name , identify_obj , opt_callback ) {
7500
+ if ( ! this . _apiKeySet ( 'groupIdentify()' ) ) {
7501
+ if ( type ( opt_callback ) === 'function' ) {
7502
+ opt_callback ( 0 , 'No request sent' , { reason : 'API key is not set' } ) ;
7503
+ }
7504
+ return ;
7505
+ }
7506
+
7507
+ if ( ! utils . validateInput ( group_type , 'group_type' , 'string' ) || utils . isEmptyString ( group_type ) ) {
7508
+ if ( type ( opt_callback ) === 'function' ) {
7509
+ opt_callback ( 0 , 'No request sent' , { reason : 'Invalid group type' } ) ;
7510
+ }
7511
+ return ;
7512
+ }
7513
+
7514
+ if ( group_name === null || group_name === undefined ) {
7515
+ if ( type ( opt_callback ) === 'function' ) {
7516
+ opt_callback ( 0 , 'No request sent' , { reason : 'Invalid group name' } ) ;
7517
+ }
7518
+ return ;
7519
+ }
7520
+
7521
+ // if identify input is a proxied object created by the async loading snippet, convert it into an identify object
7522
+ if ( type ( identify_obj ) === 'object' && identify_obj . hasOwnProperty ( '_q' ) ) {
7523
+ identify_obj = _convertProxyObjectToRealObject ( new Identify ( ) , identify_obj ) ;
7524
+ }
7525
+
7526
+ if ( identify_obj instanceof Identify ) {
7527
+ // only send if there are operations
7528
+ if ( Object . keys ( identify_obj . userPropertiesOperations ) . length > 0 ) {
7529
+ return this . _logEvent ( constants . GROUP_IDENTIFY_EVENT , null , null , null , _defineProperty ( { } , group_type , group_name ) , identify_obj . userPropertiesOperations , null , opt_callback ) ;
7530
+ } else {
7531
+ if ( type ( opt_callback ) === 'function' ) {
7532
+ opt_callback ( 0 , 'No request sent' , { reason : 'No group property operations' } ) ;
7533
+ }
7534
+ }
7535
+ } else {
7536
+ utils . log . error ( 'Invalid identify input type. Expected Identify object but saw ' + type ( identify_obj ) ) ;
7537
+ if ( type ( opt_callback ) === 'function' ) {
7538
+ opt_callback ( 0 , 'No request sent' , { reason : 'Invalid identify input type' } ) ;
7539
+ }
7540
+ }
7541
+ } ;
7542
+
7496
7543
/**
7497
7544
* Set a versionName for your application.
7498
7545
* @public
@@ -7510,7 +7557,7 @@ AmplitudeClient.prototype.setVersionName = function setVersionName(versionName)
7510
7557
* Private logEvent method. Keeps apiProperties from being publicly exposed.
7511
7558
* @private
7512
7559
*/
7513
- AmplitudeClient . prototype . _logEvent = function _logEvent ( eventType , eventProperties , apiProperties , userProperties , groups , timestamp , callback ) {
7560
+ AmplitudeClient . prototype . _logEvent = function _logEvent ( eventType , eventProperties , apiProperties , userProperties , groups , groupProperties , timestamp , callback ) {
7514
7561
_loadCookieData ( this ) ; // reload cookie before each log event to sync event meta-data between windows and tabs
7515
7562
if ( ! eventType ) {
7516
7563
if ( type ( callback ) === 'function' ) {
@@ -7527,7 +7574,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
7527
7574
7528
7575
try {
7529
7576
var eventId ;
7530
- if ( eventType === constants . IDENTIFY_EVENT ) {
7577
+ if ( eventType === constants . IDENTIFY_EVENT || eventType === constants . GROUP_IDENTIFY_EVENT ) {
7531
7578
eventId = this . nextIdentifyId ( ) ;
7532
7579
} else {
7533
7580
eventId = this . nextEventId ( ) ;
@@ -7568,10 +7615,11 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
7568
7615
} ,
7569
7616
sequence_number : sequenceNumber , // for ordering events and identifys
7570
7617
groups : utils . truncate ( utils . validateGroups ( groups ) ) ,
7618
+ group_properties : utils . truncate ( utils . validateProperties ( groupProperties ) ) ,
7571
7619
user_agent : this . _userAgent
7572
7620
} ;
7573
7621
7574
- if ( eventType === constants . IDENTIFY_EVENT ) {
7622
+ if ( eventType === constants . IDENTIFY_EVENT || eventType === constants . GROUP_IDENTIFY_EVENT ) {
7575
7623
this . _unsentIdentifys . push ( event ) ;
7576
7624
this . _limitEventsQueued ( this . _unsentIdentifys ) ;
7577
7625
} else {
@@ -7670,7 +7718,7 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
7670
7718
}
7671
7719
return - 1 ;
7672
7720
}
7673
- return this . _logEvent ( eventType , eventProperties , null , null , null , timestamp , opt_callback ) ;
7721
+ return this . _logEvent ( eventType , eventProperties , null , null , null , null , timestamp , opt_callback ) ;
7674
7722
} ;
7675
7723
7676
7724
/**
@@ -7701,7 +7749,7 @@ AmplitudeClient.prototype.logEventWithGroups = function (eventType, eventPropert
7701
7749
}
7702
7750
return - 1 ;
7703
7751
}
7704
- return this . _logEvent ( eventType , eventProperties , null , null , groups , null , opt_callback ) ;
7752
+ return this . _logEvent ( eventType , eventProperties , null , null , groups , null , null , opt_callback ) ;
7705
7753
} ;
7706
7754
7707
7755
/**
@@ -7763,7 +7811,7 @@ AmplitudeClient.prototype.logRevenue = function logRevenue(price, quantity, prod
7763
7811
special : 'revenue_amount' ,
7764
7812
quantity : quantity || 1 ,
7765
7813
price : price
7766
- } , null , null , null , null ) ;
7814
+ } , null , null , null , null , null ) ;
7767
7815
} ;
7768
7816
7769
7817
/**
0 commit comments