Skip to content

Commit ee8ebde

Browse files
committed
Identify documentation
1 parent 254fbf0 commit ee8ebde

File tree

11 files changed

+1666
-26
lines changed

11 files changed

+1666
-26
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ $(OUT): node_modules $(SRC) version
6666
@$(JSHINT) --verbose $(SRC)
6767
@$(DUO) --standalone amplitude src/index.js > $(OUT)
6868
@$(MINIFY) $(OUT) --output $(MIN_OUT)
69-
@$(JSDOC) -d ./documentation/ src/amplitude.js
69+
@$(JSDOC) -d ./documentation/ src/*.js
7070

7171
#
7272
# Target for minified `amplitude-snippet.js` file.

amplitude.js

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,17 +2289,16 @@ module.exports = {
22892289

22902290
}, {"./constants":3,"./type":12}],
22912291
12: [function(require, module, exports) {
2292-
/* Taken from: https://github.com/component/type */
2293-
22942292
/**
22952293
* toString ref.
2294+
* @private
22962295
*/
22972296

22982297
var toString = Object.prototype.toString;
22992298

23002299
/**
23012300
* Return the type of `val`.
2302-
*
2301+
* @private
23032302
* @param {Mixed} val
23042303
* @return {String}
23052304
* @api public
@@ -2487,11 +2486,32 @@ var AMP_OP_SET = '$set';
24872486
var AMP_OP_SET_ONCE = '$setOnce';
24882487
var AMP_OP_UNSET = '$unset';
24892488

2489+
/**
2490+
* Identify API - instance constructor. Identify objects are a wrapper for user property operations.
2491+
* Each method adds a user property operation to the Identify object, and returns the same Identify object,
2492+
* allowing you to chain multiple method calls together.
2493+
* Note: if the same user property is used in multiple operations on a single Identify object,
2494+
* only the first operation on that property will be saved, and the rest will be ignored.
2495+
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#user-properties-and-user-property-operations}
2496+
* for more information on the Identify API and user property operations.
2497+
* @constructor Identify
2498+
* @public
2499+
* @example var identify = new amplitude.Identify();
2500+
*/
24902501
var Identify = function() {
24912502
this.userPropertiesOperations = {};
24922503
this.properties = []; // keep track of keys that have been added
24932504
};
24942505

2506+
/**
2507+
* Increment a user property by a given value (can also be negative to decrement). If the user property does not have a value set yet, it will be initialized to 0 before being incremented.
2508+
* @public
2509+
* @param {string} property - The user property key.
2510+
* @param {number/string} value - The amount by which to increment the user property. Allows numbers as strings (ex: '123').
2511+
* @return {Identify_object} Returns the same Identify object, allowing you to chain multiple method calls together.
2512+
* @example var identify = new amplitude.Identify().add('karma', 1).add('friends', 1);
2513+
* amplitude.identify(identify); // send the Identify call
2514+
*/
24952515
Identify.prototype.add = function(property, value) {
24962516
if (type(value) === 'number' || type(value) === 'string') {
24972517
this._addOperation(AMP_OP_ADD, property, value);
@@ -2501,14 +2521,30 @@ Identify.prototype.add = function(property, value) {
25012521
return this;
25022522
};
25032523

2524+
/**
2525+
* Append a value or values to a user property.
2526+
* If the user property does not have a value set yet, it will be initialized to an empty list before the new values are appended.
2527+
* If the user property has an existing value and it is not a list, the existing value will be converted into a list with the new values appended.
2528+
* @public
2529+
* @param {string} property - The user property key.
2530+
* @param {number/string/list/object} value - A value or values to append. Values can be numbers, strings, lists, or object (key:value dict will be flattened).
2531+
* @return {Identify_object} Returns the same Identify object, allowing you to chain multiple method calls together.
2532+
* @example var identify = new amplitude.Identify().append('ab-tests', 'new-user-tests');
2533+
* identify.append('some_list', [1, 2, 3, 4, 'values']);
2534+
* amplitude.identify(identify); // send the Identify call
2535+
*/
25042536
Identify.prototype.append = function(property, value) {
25052537
this._addOperation(AMP_OP_APPEND, property, value);
25062538
return this;
25072539
};
25082540

2509-
// clearAll should be sent on its own Identify object
2510-
// If there are already other operations, then don't add clearAll
2511-
// If clearAll already in Identify, don't add other operations
2541+
/**
2542+
* Clear all user properties for the current user.
2543+
* SDK user should instead call amplitude.clearUserProperties() instead of using this.
2544+
* $clearAll needs to be sent on its own Identify object. If there are already other operations, then don't add $clearAll.
2545+
* If $clearAll already in an Identify object, don't allow other operations to be added.
2546+
* @private
2547+
*/
25122548
Identify.prototype.clearAll = function() {
25132549
if (Object.keys(this.userPropertiesOperations).length > 0) {
25142550
if (!this.userPropertiesOperations.hasOwnProperty(AMP_OP_CLEAR_ALL)) {
@@ -2520,26 +2556,71 @@ Identify.prototype.clearAll = function() {
25202556
return this;
25212557
};
25222558

2559+
/**
2560+
* Prepend a value or values to a user property. Prepend means inserting the value or values at the front of a list.
2561+
* If the user property does not have a value set yet, it will be initialized to an empty list before the new values are prepended.
2562+
* If the user property has an existing value and it is not a list, the existing value will be converted into a list with the new values prepended.
2563+
* @public
2564+
* @param {string} property - The user property key.
2565+
* @param {number/string/list/object} value - A value or values to prepend. Values can be numbers, strings, lists, or object (key:value dict will be flattened).
2566+
* @return {Identify_object} Returns the same Identify object, allowing you to chain multiple method calls together.
2567+
* @example var identify = new amplitude.Identify().prepend('ab-tests', 'new-user-tests');
2568+
* identify.prepend('some_list', [1, 2, 3, 4, 'values']);
2569+
* amplitude.identify(identify); // send the Identify call
2570+
*/
25232571
Identify.prototype.prepend = function(property, value) {
25242572
this._addOperation(AMP_OP_PREPEND, property, value);
25252573
return this;
25262574
};
25272575

2576+
/**
2577+
* Sets the value of a given user property. If a value already exists, it will be overwriten with the new value.
2578+
* @public
2579+
* @param {string} property - The user property key.
2580+
* @param {number/string/list/object} value - A value or values to set. Values can be numbers, strings, lists, or object (key:value dict will be flattened).
2581+
* @return {Identify_object} Returns the same Identify object, allowing you to chain multiple method calls together.
2582+
* @example var identify = new amplitude.Identify().set('user_type', 'beta');
2583+
* identify.set('name', {'first': 'John', 'last': 'Doe'}); // dict is flattened and becomes name.first: John, name.last: Doe
2584+
* amplitude.identify(identify); // send the Identify call
2585+
*/
25282586
Identify.prototype.set = function(property, value) {
25292587
this._addOperation(AMP_OP_SET, property, value);
25302588
return this;
25312589
};
25322590

2591+
/**
2592+
* Sets the value of a given user property only once. Subsequent setOnce operations on that user property will be ignored; however, that user property can still be modified through any of the other operations.
2593+
* Useful for capturing properties such as 'initial_signup_date', 'initial_referrer', etc.
2594+
* @public
2595+
* @param {string} property - The user property key.
2596+
* @param {number/string/list/object} value - A value or values to set once. Values can be numbers, strings, lists, or object (key:value dict will be flattened).
2597+
* @return {Identify_object} Returns the same Identify object, allowing you to chain multiple method calls together.
2598+
* @example var identify = new amplitude.Identify().setOnce('sign_up_date', '2016-04-01');
2599+
* amplitude.identify(identify); // send the Identify call
2600+
*/
25332601
Identify.prototype.setOnce = function(property, value) {
25342602
this._addOperation(AMP_OP_SET_ONCE, property, value);
25352603
return this;
25362604
};
25372605

2606+
/**
2607+
* Unset and remove a user property. This user property will no longer show up in a user's profile.
2608+
* @public
2609+
* @param {string} property - The user property key.
2610+
* @return {Identify_object} Returns the same Identify object, allowing you to chain multiple method calls together.
2611+
* @example var identify = new amplitude.Identify().unset('user_type').unset('age');
2612+
* amplitude.identify(identify); // send the Identify call
2613+
*/
25382614
Identify.prototype.unset = function(property) {
25392615
this._addOperation(AMP_OP_UNSET, property, '-');
25402616
return this;
25412617
};
25422618

2619+
/**
2620+
* Helper function that adds operation to the Identify's object
2621+
* Handle's filtering of duplicate user property keys, and filtering for clearAll.
2622+
* @private
2623+
*/
25432624
Identify.prototype._addOperation = function(operation, property, value) {
25442625
// check that the identify doesn't already contain a clearAll
25452626
if (this.userPropertiesOperations.hasOwnProperty(AMP_OP_CLEAR_ALL)) {
@@ -4016,13 +4097,13 @@ function isBuffer(obj) {
40164097
/* jshint bitwise: false, laxbreak: true */
40174098

40184099
/**
4019-
* Taken straight from jed's gist: https://gist.github.com/982883
4020-
*
4100+
* Source: [jed's gist]{@link https://gist.github.com/982883}.
40214101
* Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
40224102
* where each x is replaced with a random hexadecimal digit from 0 to f, and
40234103
* y is replaced with a random hexadecimal digit from 8 to b.
4104+
* Used to generate UUIDs for deviceIds.
4105+
* @private
40244106
*/
4025-
40264107
var uuid = function(a) {
40274108
return a // if the placeholder was passed, return
40284109
? ( // a random number from 0 to 15

documentation/Amplitude.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,13 +2314,13 @@ <h5>Example</h5>
23142314
</div>
23152315

23162316
<nav>
2317-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude.html">Amplitude</a></li></ul>
2317+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude.html">Amplitude</a></li><li><a href="Identify.html">Identify</a></li></ul>
23182318
</nav>
23192319

23202320
<br class="clear">
23212321

23222322
<footer>
2323-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Fri Apr 01 2016 15:10:18 GMT-0700 (PDT)
2323+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Fri Apr 01 2016 16:04:25 GMT-0700 (PDT)
23242324
</footer>
23252325

23262326
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)