@@ -925,6 +925,7 @@ var constants = {
925925 MAX_STRING_LENGTH : 4096 ,
926926 MAX_PROPERTY_KEYS : 1000 ,
927927 IDENTIFY_EVENT : '$identify' ,
928+ GROUP_IDENTIFY_EVENT : '$groupidentify' ,
928929
929930 // localStorageKeys
930931 LAST_EVENT_ID : 'amplitude_lastEventId' ,
@@ -3977,7 +3978,7 @@ var defineProperty = (function() {
39773978 } catch ( e ) { }
39783979} ( ) ) ;
39793980
3980- var _defineProperty = defineProperty ;
3981+ var _defineProperty$1 = defineProperty ;
39813982
39823983/**
39833984 * The base implementation of `assignValue` and `assignMergeValue` without
@@ -3989,8 +3990,8 @@ var _defineProperty = defineProperty;
39893990 * @param {* } value The value to assign.
39903991 */
39913992function baseAssignValue ( object , key , value ) {
3992- if ( key == '__proto__' && _defineProperty ) {
3993- _defineProperty ( object , key , {
3993+ if ( key == '__proto__' && _defineProperty$1 ) {
3994+ _defineProperty$1 ( object , key , {
39943995 'configurable' : true ,
39953996 'enumerable' : true ,
39963997 'value' : value ,
@@ -5167,8 +5168,8 @@ var constant_1 = constant;
51675168 * @param {Function } string The `toString` result.
51685169 * @returns {Function } Returns `func`.
51695170 */
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' , {
51725173 'configurable' : true ,
51735174 'enumerable' : false ,
51745175 'value' : constant_1 ( string ) ,
@@ -6665,6 +6666,8 @@ var DEFAULT_OPTIONS = {
66656666 uploadBatchSize : 100
66666667} ;
66676668
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+
66686671/**
66696672 * AmplitudeClient SDK API - instance constructor.
66706673 * 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) {
73217324 var groups = { } ;
73227325 groups [ groupType ] = groupName ;
73237326 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 ) ;
73257328} ;
73267329
73277330/**
@@ -7479,7 +7482,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
74797482 if ( identify_obj instanceof Identify ) {
74807483 // only send if there are operations
74817484 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 ) ;
74837486 } else {
74847487 if ( type ( opt_callback ) === 'function' ) {
74857488 opt_callback ( 0 , 'No request sent' , { reason : 'No user property operations' } ) ;
@@ -7493,6 +7496,50 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
74937496 }
74947497} ;
74957498
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+
74967543/**
74977544 * Set a versionName for your application.
74987545 * @public
@@ -7510,7 +7557,7 @@ AmplitudeClient.prototype.setVersionName = function setVersionName(versionName)
75107557 * Private logEvent method. Keeps apiProperties from being publicly exposed.
75117558 * @private
75127559 */
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 ) {
75147561 _loadCookieData ( this ) ; // reload cookie before each log event to sync event meta-data between windows and tabs
75157562 if ( ! eventType ) {
75167563 if ( type ( callback ) === 'function' ) {
@@ -7527,7 +7574,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
75277574
75287575 try {
75297576 var eventId ;
7530- if ( eventType === constants . IDENTIFY_EVENT ) {
7577+ if ( eventType === constants . IDENTIFY_EVENT || eventType === constants . GROUP_IDENTIFY_EVENT ) {
75317578 eventId = this . nextIdentifyId ( ) ;
75327579 } else {
75337580 eventId = this . nextEventId ( ) ;
@@ -7568,10 +7615,11 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
75687615 } ,
75697616 sequence_number : sequenceNumber , // for ordering events and identifys
75707617 groups : utils . truncate ( utils . validateGroups ( groups ) ) ,
7618+ group_properties : utils . truncate ( utils . validateProperties ( groupProperties ) ) ,
75717619 user_agent : this . _userAgent
75727620 } ;
75737621
7574- if ( eventType === constants . IDENTIFY_EVENT ) {
7622+ if ( eventType === constants . IDENTIFY_EVENT || eventType === constants . GROUP_IDENTIFY_EVENT ) {
75757623 this . _unsentIdentifys . push ( event ) ;
75767624 this . _limitEventsQueued ( this . _unsentIdentifys ) ;
75777625 } else {
@@ -7670,7 +7718,7 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
76707718 }
76717719 return - 1 ;
76727720 }
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 ) ;
76747722} ;
76757723
76767724/**
@@ -7701,7 +7749,7 @@ AmplitudeClient.prototype.logEventWithGroups = function (eventType, eventPropert
77017749 }
77027750 return - 1 ;
77037751 }
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 ) ;
77057753} ;
77067754
77077755/**
@@ -7763,7 +7811,7 @@ AmplitudeClient.prototype.logRevenue = function logRevenue(price, quantity, prod
77637811 special : 'revenue_amount' ,
77647812 quantity : quantity || 1 ,
77657813 price : price
7766- } , null , null , null , null ) ;
7814+ } , null , null , null , null , null ) ;
77677815} ;
77687816
77697817/**
0 commit comments