Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions amplitude-segment-snippet.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ var i=function(){this._q=[];return this}
;return this}
;var u=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]
;for(var c=0;c<u.length;c++){r(a,u[c])}n.Revenue=a
;var l=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
;function p(e){function t(t){e[t]=function(){
;var p=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
;function l(e){function t(t){e[t]=function(){
e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}
for(var n=0;n<l.length;n++){t(l[n])}}p(n);n.getInstance=function(e){
for(var n=0;n<p.length;n++){t(p[n])}}l(n);n.getInstance=function(e){
e=(!e||e.length===0?"$default_instance":e).toLowerCase()
;if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};p(n._iq[e])}return n._iq[e]}
;if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};l(n._iq[e])}return n._iq[e]}
;e.amplitude=n})(window,document);
2 changes: 1 addition & 1 deletion amplitude-snippet.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var o=function(){this._q=[];return this}
;return this}
;var l=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]
;for(var p=0;p<l.length;p++){s(c,l[p])}n.Revenue=c
;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
;function v(e){function t(t){e[t]=function(){
e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}
for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){
Expand Down
74 changes: 61 additions & 13 deletions amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ var constants = {
MAX_STRING_LENGTH: 4096,
MAX_PROPERTY_KEYS: 1000,
IDENTIFY_EVENT: '$identify',
GROUP_IDENTIFY_EVENT: '$groupidentify',

// localStorageKeys
LAST_EVENT_ID: 'amplitude_lastEventId',
Expand Down Expand Up @@ -3977,7 +3978,7 @@ var defineProperty = (function() {
} catch (e) {}
}());

var _defineProperty = defineProperty;
var _defineProperty$1 = defineProperty;

/**
* The base implementation of `assignValue` and `assignMergeValue` without
Expand All @@ -3989,8 +3990,8 @@ var _defineProperty = defineProperty;
* @param {*} value The value to assign.
*/
function baseAssignValue(object, key, value) {
if (key == '__proto__' && _defineProperty) {
_defineProperty(object, key, {
if (key == '__proto__' && _defineProperty$1) {
_defineProperty$1(object, key, {
'configurable': true,
'enumerable': true,
'value': value,
Expand Down Expand Up @@ -5167,8 +5168,8 @@ var constant_1 = constant;
* @param {Function} string The `toString` result.
* @returns {Function} Returns `func`.
*/
var baseSetToString = !_defineProperty ? identity_1 : function(func, string) {
return _defineProperty(func, 'toString', {
var baseSetToString = !_defineProperty$1 ? identity_1 : function(func, string) {
return _defineProperty$1(func, 'toString', {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this $1 mean?

'configurable': true,
'enumerable': false,
'value': constant_1(string),
Expand Down Expand Up @@ -6665,6 +6666,8 @@ var DEFAULT_OPTIONS = {
uploadBatchSize: 100
};

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; }

/**
* AmplitudeClient SDK API - instance constructor.
* The Amplitude class handles creation of client instances, all you need to do is call amplitude.getInstance()
Expand Down Expand Up @@ -7321,7 +7324,7 @@ AmplitudeClient.prototype.setGroup = function (groupType, groupName) {
var groups = {};
groups[groupType] = groupName;
var identify = new Identify().set(groupType, groupName);
this._logEvent(constants.IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null, null);
this._logEvent(constants.IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null, null, null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a GROUP_IDENTIFY_EVENT? and groupPropertiesOpeations?

};

/**
Expand Down Expand Up @@ -7479,7 +7482,7 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
if (identify_obj instanceof Identify) {
// only send if there are operations
if (Object.keys(identify_obj.userPropertiesOperations).length > 0) {
return this._logEvent(constants.IDENTIFY_EVENT, null, null, identify_obj.userPropertiesOperations, null, null, opt_callback);
return this._logEvent(constants.IDENTIFY_EVENT, null, null, identify_obj.userPropertiesOperations, null, null, null, opt_callback);
} else {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', { reason: 'No user property operations' });
Expand All @@ -7493,6 +7496,50 @@ AmplitudeClient.prototype.identify = function (identify_obj, opt_callback) {
}
};

AmplitudeClient.prototype.groupIdentify = function (group_type, group_name, identify_obj, opt_callback) {
if (!this._apiKeySet('groupIdentify()')) {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', { reason: 'API key is not set' });
}
return;
}

if (!utils.validateInput(group_type, 'group_type', 'string') || utils.isEmptyString(group_type)) {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', { reason: 'Invalid group type' });
}
return;
}

if (group_name === null || group_name === undefined) {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', { reason: 'Invalid group name' });
}
return;
}

// if identify input is a proxied object created by the async loading snippet, convert it into an identify object
if (type(identify_obj) === 'object' && identify_obj.hasOwnProperty('_q')) {
identify_obj = _convertProxyObjectToRealObject(new Identify(), identify_obj);
}

if (identify_obj instanceof Identify) {
// only send if there are operations
if (Object.keys(identify_obj.userPropertiesOperations).length > 0) {
return this._logEvent(constants.GROUP_IDENTIFY_EVENT, null, null, null, _defineProperty({}, group_type, group_name), identify_obj.userPropertiesOperations, null, opt_callback);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems we have the GROUP_IDENTIFY_EVENT, do we need groupPropertiesOpeations?

} else {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', { reason: 'No group property operations' });
}
}
} else {
utils.log.error('Invalid identify input type. Expected Identify object but saw ' + type(identify_obj));
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', { reason: 'Invalid identify input type' });
}
}
};

/**
* Set a versionName for your application.
* @public
Expand All @@ -7510,7 +7557,7 @@ AmplitudeClient.prototype.setVersionName = function setVersionName(versionName)
* Private logEvent method. Keeps apiProperties from being publicly exposed.
* @private
*/
AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventProperties, apiProperties, userProperties, groups, timestamp, callback) {
AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventProperties, apiProperties, userProperties, groups, groupProperties, timestamp, callback) {
_loadCookieData(this); // reload cookie before each log event to sync event meta-data between windows and tabs
if (!eventType) {
if (type(callback) === 'function') {
Expand All @@ -7527,7 +7574,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert

try {
var eventId;
if (eventType === constants.IDENTIFY_EVENT) {
if (eventType === constants.IDENTIFY_EVENT || eventType === constants.GROUP_IDENTIFY_EVENT) {
eventId = this.nextIdentifyId();
} else {
eventId = this.nextEventId();
Expand Down Expand Up @@ -7568,10 +7615,11 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
},
sequence_number: sequenceNumber, // for ordering events and identifys
groups: utils.truncate(utils.validateGroups(groups)),
group_properties: utils.truncate(utils.validateProperties(groupProperties)),
user_agent: this._userAgent
};

if (eventType === constants.IDENTIFY_EVENT) {
if (eventType === constants.IDENTIFY_EVENT || eventType === constants.GROUP_IDENTIFY_EVENT) {
this._unsentIdentifys.push(event);
this._limitEventsQueued(this._unsentIdentifys);
} else {
Expand Down Expand Up @@ -7670,7 +7718,7 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
}
return -1;
}
return this._logEvent(eventType, eventProperties, null, null, null, timestamp, opt_callback);
return this._logEvent(eventType, eventProperties, null, null, null, null, timestamp, opt_callback);
};

/**
Expand Down Expand Up @@ -7701,7 +7749,7 @@ AmplitudeClient.prototype.logEventWithGroups = function (eventType, eventPropert
}
return -1;
}
return this._logEvent(eventType, eventProperties, null, null, groups, null, opt_callback);
return this._logEvent(eventType, eventProperties, null, null, groups, null, null, opt_callback);
};

/**
Expand Down Expand Up @@ -7763,7 +7811,7 @@ AmplitudeClient.prototype.logRevenue = function logRevenue(price, quantity, prod
special: 'revenue_amount',
quantity: quantity || 1,
price: price
}, null, null, null, null);
}, null, null, null, null, null);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion amplitude.min.js

Large diffs are not rendered by default.

64 changes: 56 additions & 8 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ AmplitudeClient.prototype.setGroup = function(groupType, groupName) {
var groups = {};
groups[groupType] = groupName;
var identify = new Identify().set(groupType, groupName);
this._logEvent(Constants.IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null, null);
this._logEvent(Constants.IDENTIFY_EVENT, null, null, identify.userPropertiesOperations, groups, null, null, null);
};

/**
Expand Down Expand Up @@ -837,7 +837,7 @@ AmplitudeClient.prototype.identify = function(identify_obj, opt_callback) {
// only send if there are operations
if (Object.keys(identify_obj.userPropertiesOperations).length > 0) {
return this._logEvent(
Constants.IDENTIFY_EVENT, null, null, identify_obj.userPropertiesOperations, null, null, opt_callback
Constants.IDENTIFY_EVENT, null, null, identify_obj.userPropertiesOperations, null, null, null, opt_callback
);
} else {
if (type(opt_callback) === 'function') {
Expand All @@ -852,6 +852,53 @@ AmplitudeClient.prototype.identify = function(identify_obj, opt_callback) {
}
};

AmplitudeClient.prototype.groupIdentify = function(group_type, group_name, identify_obj, opt_callback) {
if (!this._apiKeySet('groupIdentify()')) {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', {reason: 'API key is not set'});
}
return;
}

if (!utils.validateInput(group_type, 'group_type', 'string') ||
utils.isEmptyString(group_type)) {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', {reason: 'Invalid group type'});
}
return;
}

if (group_name === null || group_name === undefined) {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', {reason: 'Invalid group name'});
}
return;
}

// if identify input is a proxied object created by the async loading snippet, convert it into an identify object
if (type(identify_obj) === 'object' && identify_obj.hasOwnProperty('_q')) {
identify_obj = _convertProxyObjectToRealObject(new Identify(), identify_obj);
}

if (identify_obj instanceof Identify) {
// only send if there are operations
if (Object.keys(identify_obj.userPropertiesOperations).length > 0) {
return this._logEvent(
Constants.GROUP_IDENTIFY_EVENT, null, null, null, {[group_type]: group_name}, identify_obj.userPropertiesOperations, null, opt_callback
);
} else {
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', {reason: 'No group property operations'});
}
}
} else {
utils.log.error('Invalid identify input type. Expected Identify object but saw ' + type(identify_obj));
if (type(opt_callback) === 'function') {
opt_callback(0, 'No request sent', {reason: 'Invalid identify input type'});
}
}
};

/**
* Set a versionName for your application.
* @public
Expand All @@ -869,7 +916,7 @@ AmplitudeClient.prototype.setVersionName = function setVersionName(versionName)
* Private logEvent method. Keeps apiProperties from being publicly exposed.
* @private
*/
AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventProperties, apiProperties, userProperties, groups, timestamp, callback) {
AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventProperties, apiProperties, userProperties, groups, groupProperties, timestamp, callback) {
_loadCookieData(this); // reload cookie before each log event to sync event meta-data between windows and tabs
if (!eventType) {
if (type(callback) === 'function') {
Expand All @@ -886,7 +933,7 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert

try {
var eventId;
if (eventType === Constants.IDENTIFY_EVENT) {
if (eventType === Constants.IDENTIFY_EVENT || eventType === Constants.GROUP_IDENTIFY_EVENT) {
eventId = this.nextIdentifyId();
} else {
eventId = this.nextEventId();
Expand Down Expand Up @@ -927,10 +974,11 @@ AmplitudeClient.prototype._logEvent = function _logEvent(eventType, eventPropert
},
sequence_number: sequenceNumber, // for ordering events and identifys
groups: utils.truncate(utils.validateGroups(groups)),
group_properties: utils.truncate(utils.validateProperties(groupProperties)),
user_agent: this._userAgent
};

if (eventType === Constants.IDENTIFY_EVENT) {
if (eventType === Constants.IDENTIFY_EVENT || eventType === Constants.GROUP_IDENTIFY_EVENT) {
this._unsentIdentifys.push(event);
this._limitEventsQueued(this._unsentIdentifys);
} else {
Expand Down Expand Up @@ -1029,7 +1077,7 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
}
return -1;
}
return this._logEvent(eventType, eventProperties, null, null, null, timestamp, opt_callback);
return this._logEvent(eventType, eventProperties, null, null, null, null, timestamp, opt_callback);
};

/**
Expand Down Expand Up @@ -1060,7 +1108,7 @@ AmplitudeClient.prototype.logEventWithGroups = function(eventType, eventProperti
}
return -1;
}
return this._logEvent(eventType, eventProperties, null, null, groups, null, opt_callback);
return this._logEvent(eventType, eventProperties, null, null, groups, null, null, opt_callback);
};

/**
Expand Down Expand Up @@ -1122,7 +1170,7 @@ AmplitudeClient.prototype.logRevenue = function logRevenue(price, quantity, prod
special: 'revenue_amount',
quantity: quantity || 1,
price: price
}, null, null, null, null);
}, null, null, null, null, null);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/amplitude-snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var funcs = ['init', 'logEvent', 'logRevenue', 'setUserId', 'setUserProperties',
'setOptOut', 'setVersionName', 'setDomain', 'setDeviceId',
'setGlobalUserProperties', 'identify', 'clearUserProperties',
'setGroup', 'logRevenueV2', 'regenerateDeviceId',
'setGroup', 'logRevenueV2', 'regenerateDeviceId', 'groupIdentify',
'logEventWithTimestamp', 'logEventWithGroups', 'setSessionId', 'resetSessionId'];
function setUpProxy(instance) {
function proxyMain(fn) {
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default {
MAX_STRING_LENGTH: 4096,
MAX_PROPERTY_KEYS: 1000,
IDENTIFY_EVENT: '$identify',
GROUP_IDENTIFY_EVENT: '$groupidentify',

// localStorageKeys
LAST_EVENT_ID: 'amplitude_lastEventId',
Expand Down
Loading