Skip to content

Commit 48e226e

Browse files
authored
Fix docs (#293)
* fix multiple param/return types generation * fix dead links * clean up docs spacing and content * fix deprecated notes in amplitude.js * Add style support for deprecated docs * Add admonitions
1 parent c888c56 commit 48e226e

File tree

6 files changed

+62
-69
lines changed

6 files changed

+62
-69
lines changed

src/amplitude-client.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ AmplitudeClient.prototype.Revenue = Revenue;
7070
* @param {string} apiKey - The API key for your app.
7171
* @param {string} opt_userId - (optional) An identifier for this user.
7272
* @param {object} opt_config - (optional) Configuration options.
73-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#configuration-options} for list of options and default values.
73+
* See [options.js](https://github.com/amplitude/Amplitude-JavaScript/blob/master/src/options.js#L14) for list of options and default values.
7474
* @param {function} opt_callback - (optional) Provide a callback function to run after initialization is complete.
7575
* @example amplitudeClient.init('API_KEY', 'USER_ID', {includeReferrer: true, includeUtm: true}, function() { alert('init complete'); });
7676
*/
@@ -858,12 +858,14 @@ AmplitudeClient.prototype.setUserId = function setUserId(userId) {
858858

859859
/**
860860
* Add user to a group or groups. You need to specify a groupType and groupName(s).
861+
*
861862
* For example you can group people by their organization.
862-
* In that case groupType is "orgId" and groupName would be the actual ID(s).
863+
* In that case, groupType is "orgId" and groupName would be the actual ID(s).
863864
* groupName can be a string or an array of strings to indicate a user in multiple gruups.
864865
* You can also call setGroup multiple times with different groupTypes to track multiple types of groups (up to 5 per app).
866+
*
865867
* Note: this will also set groupType: groupName as a user property.
866-
* See the [SDK Readme]{@link https://github.com/amplitude/Amplitude-Javascript#setting-groups} for more information.
868+
* See the [advanced topics article](https://developers.amplitude.com/docs/setting-user-groups) for more information.
867869
* @public
868870
* @param {string} groupType - the group type (ex: orgId)
869871
* @param {string|list} groupName - the name of the group (ex: 15), or a list of names of the groups
@@ -1034,8 +1036,8 @@ var _convertProxyObjectToRealObject = function _convertProxyObjectToRealObject(i
10341036

10351037
/**
10361038
* Send an identify call containing user property operations to Amplitude servers.
1037-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#user-properties-and-user-property-operations}
1038-
* for more information on the Identify API and user property operations.
1039+
* See the [Identify](https://amplitude.github.io/Amplitude-JavaScript/Identify/)
1040+
* reference page for more information on the Identify API and user property operations.
10391041
* @param {Identify} identify_obj - the Identify object containing the user property operations to send.
10401042
* @param {Amplitude~eventCallback} opt_callback - (optional) callback function to run when the identify event has been sent.
10411043
* Note: the server response code and response body from the identify event upload are passed to the callback function.
@@ -1344,7 +1346,8 @@ AmplitudeClient.prototype.logEventWithTimestamp = function logEvent(eventType, e
13441346
* Log an event with eventType, eventProperties, and groups. Use this to set event-level groups.
13451347
* Note: the group(s) set only apply for the specific event type being logged and does not persist on the user
13461348
* (unless you explicitly set it with setGroup).
1347-
* See the [SDK Readme]{@link https://github.com/amplitude/Amplitude-Javascript#setting-groups} for more information
1349+
*
1350+
* See the [advanced topics article](https://developers.amplitude.com/docs/setting-user-groups) for more information.
13481351
* about groups and Count by Distinct on the Amplitude platform.
13491352
* @public
13501353
* @param {string} eventType - name of event
@@ -1385,8 +1388,9 @@ var _isNumber = function _isNumber(n) {
13851388
/**
13861389
* Log revenue with Revenue interface. The new revenue interface allows for more revenue fields like
13871390
* revenueType and event properties.
1388-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#tracking-revenue}
1389-
* for more information on the Revenue interface and logging revenue.
1391+
*
1392+
* See the [Revenue](https://amplitude.github.io/Amplitude-JavaScript/Revenue/)
1393+
* reference page for more information on the Revenue interface and logging revenue.
13901394
* @public
13911395
* @param {Revenue} revenue_obj - the revenue object containing the revenue data being logged.
13921396
* @example var revenue = new amplitude.Revenue().setProductId('productIdentifier').setPrice(10.99);

src/amplitude.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import { version } from '../package.json';
88
import DEFAULT_OPTIONS from './options';
99

1010
/**
11-
* Legacy API of Amplitude SDK - instance manager. Wraps around the current amplitude-client.js which provides more features
11+
* Deprecated legacy API of the Amplitude JS SDK - instance manager.
12+
*
13+
* Wraps around the current [AmplitudeClient](https://amplitude.github.io/Amplitude-JavaScript/) which provides more features
1214
* Function calls directly on amplitude have been deprecated. Please call methods on the default shared instance: amplitude.getInstance() instead.
13-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#300-update-and-logging-events-to-multiple-amplitude-apps} for more information about this change.
15+
*
16+
* See the [3.0.0 changelog](https://github.com/amplitude/Amplitude-JavaScript/blob/ed405afb5f06d5cf5b72539a5d09179abcf7e1fe/README.md#300-update-and-logging-events-to-multiple-amplitude-apps) for more information about this change.
1417
* @constructor Amplitude
1518
* @public
19+
* @deprecated
1620
* @example var amplitude = new Amplitude();
1721
*/
1822
var Amplitude = function Amplitude() {
@@ -66,7 +70,7 @@ if (BUILD_COMPAT_2_0) {
6670
* @param {string} apiKey - The API key for your app.
6771
* @param {string} opt_userId - (optional) An identifier for this user.
6872
* @param {object} opt_config - (optional) Configuration options.
69-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#configuration-options} for list of options and default values.
73+
* See [options.js](https://github.com/amplitude/Amplitude-JavaScript/blob/master/src/options.js#L14) for list of options and default values.
7074
* @param {function} opt_callback - (optional) Provide a callback function to run after initialization is complete.
7175
* @deprecated Please use amplitude.getInstance().init(apiKey, opt_userId, opt_config, opt_callback);
7276
* @example amplitude.init('API_KEY', 'USER_ID', {includeReferrer: true, includeUtm: true}, function() { alert('init complete'); });
@@ -163,7 +167,7 @@ if (BUILD_COMPAT_2_0) {
163167
* groupName can be a string or an array of strings to indicate a user in multiple gruups.
164168
* You can also call setGroup multiple times with different groupTypes to track multiple types of groups (up to 5 per app).
165169
* Note: this will also set groupType: groupName as a user property.
166-
* See the [SDK Readme]{@link https://github.com/amplitude/Amplitude-Javascript#setting-groups} for more information.
170+
* See the [advanced topics article](https://developers.amplitude.com/docs/setting-user-groups) for more information.
167171
* @public
168172
* @param {string} groupType - the group type (ex: orgId)
169173
* @param {string|list} groupName - the name of the group (ex: 15), or a list of names of the groups
@@ -199,7 +203,9 @@ if (BUILD_COMPAT_2_0) {
199203

200204
/**
201205
* Sets a custom deviceId for current user. Note: this is not recommended unless you know what you are doing
202-
* (like if you have your own system for managing deviceIds). Make sure the deviceId you set is sufficiently unique
206+
* (like if you have your own system for managing deviceIds).
207+
*
208+
* Make sure the deviceId you set is sufficiently unique
203209
* (we recommend something like a UUID - see src/uuid.js for an example of how to generate) to prevent conflicts with other devices in our system.
204210
* @public
205211
* @param {string} deviceId - custom deviceId for current user.
@@ -213,10 +219,10 @@ if (BUILD_COMPAT_2_0) {
213219
/**
214220
* Sets user properties for the current user.
215221
* @public
216-
* @param {object} - object with string keys and values for the user properties to set.
217-
* @param {boolean} - DEPRECATED opt_replace: in earlier versions of the JS SDK the user properties object was kept in
222+
* @param {object} userProperties - object with string keys and values for the user properties to set.
223+
* @param {boolean} opt_replace - Deprecated. In earlier versions of the JS SDK the user properties object was kept in
218224
* memory and replace = true would replace the object in memory. Now the properties are no longer stored in memory, so replace is deprecated.
219-
* @deprecated Please use amplitude.getInstance.setUserProperties(userProperties);
225+
* @deprecated Please use amplitude.getInstance().setUserProperties(userProperties);
220226
* @example amplitude.setUserProperties({'gender': 'female', 'sign_up_complete': true})
221227
*/
222228
Amplitude.prototype.setUserProperties = function setUserProperties(userProperties) {
@@ -235,8 +241,8 @@ if (BUILD_COMPAT_2_0) {
235241

236242
/**
237243
* Send an identify call containing user property operations to Amplitude servers.
238-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#user-properties-and-user-property-operations}
239-
* for more information on the Identify API and user property operations.
244+
* See the [Identify](https://amplitude.github.io/Amplitude-JavaScript/Identify/)
245+
* reference page for more information on the Identify API and user property operations.
240246
* @param {Identify} identify_obj - the Identify object containing the user property operations to send.
241247
* @param {Amplitude~eventCallback} opt_callback - (optional) callback function to run when the identify event has been sent.
242248
* Note: the server response code and response body from the identify event upload are passed to the callback function.
@@ -284,9 +290,11 @@ if (BUILD_COMPAT_2_0) {
284290

285291
/**
286292
* Log an event with eventType, eventProperties, and groups. Use this to set event-level groups.
293+
*
287294
* Note: the group(s) set only apply for the specific event type being logged and does not persist on the user
288295
* (unless you explicitly set it with setGroup).
289-
* See the [SDK Readme]{@link https://github.com/amplitude/Amplitude-Javascript#setting-groups} for more information
296+
*
297+
* See the [advanced topics article](https://developers.amplitude.com/docs/setting-user-groups) for more information.
290298
* about groups and Count by Distinct on the Amplitude platform.
291299
* @public
292300
* @param {string} eventType - name of event
@@ -295,7 +303,7 @@ if (BUILD_COMPAT_2_0) {
295303
* groupName can be a string or an array of strings.
296304
* @param {Amplitude~eventCallback} opt_callback - (optional) a callback function to run after the event is logged.
297305
* Note: the server response code and response body from the event upload are passed to the callback function.
298-
* Deprecated Please use amplitude.getInstance().logEventWithGroups(eventType, eventProperties, groups, opt_callback);
306+
* @deprecated Please use amplitude.getInstance().logEventWithGroups(eventType, eventProperties, groups, opt_callback);
299307
* @example amplitude.logEventWithGroups('Clicked Button', null, {'orgId': 24});
300308
*/
301309
Amplitude.prototype.logEventWithGroups = function(eventType, eventProperties, groups, opt_callback) {
@@ -305,8 +313,9 @@ if (BUILD_COMPAT_2_0) {
305313
/**
306314
* Log revenue with Revenue interface. The new revenue interface allows for more revenue fields like
307315
* revenueType and event properties.
308-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#tracking-revenue}
309-
* for more information on the Revenue interface and logging revenue.
316+
*
317+
* See the [Revenue](https://amplitude.github.io/Amplitude-JavaScript/Revenue/)
318+
* reference page for more information on the Revenue interface and logging revenue.
310319
* @public
311320
* @param {Revenue} revenue_obj - the revenue object containing the revenue data being logged.
312321
* @deprecated Please use amplitude.getInstance().logRevenueV2(revenue_obj);
@@ -318,7 +327,7 @@ if (BUILD_COMPAT_2_0) {
318327
};
319328

320329
/**
321-
* Log revenue event with a price, quantity, and product identifier. DEPRECATED - use logRevenueV2
330+
* Log revenue event with a price, quantity, and product identifier.
322331
* @public
323332
* @param {number} price - price of revenue event
324333
* @param {number} quantity - (optional) quantity of products in revenue event. If no quantity specified default to 1.
@@ -350,9 +359,9 @@ if (BUILD_COMPAT_2_0) {
350359
};
351360

352361
/**
353-
* Set global user properties. Note this is deprecated, and we recommend using setUserProperties
362+
* Set global user properties.
354363
* @public
355-
* @deprecated
364+
* @deprecated Please use amplitudeClient.setUserProperties
356365
*/
357366
Amplitude.prototype.setGlobalUserProperties = function setGlobalUserProperties(userProperties) {
358367
this.getInstance().setUserProperties(userProperties);

src/identify.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var AMP_OP_UNSET = '$unset';
2121
* allowing you to chain multiple method calls together.
2222
* Note: if the same user property is used in multiple operations on a single Identify object,
2323
* only the first operation on that property will be saved, and the rest will be ignored.
24-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#user-properties-and-user-property-operations}
25-
* for more information on the Identify API and user property operations.
2624
* @constructor Identify
2725
* @public
2826
* @example var identify = new amplitude.Identify();

src/revenue.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ import constants from './constants';
22
import type from './type';
33
import utils from './utils';
44

5-
/*
6-
* Wrapper for logging Revenue data. Revenue objects get passed to amplitude.logRevenueV2 to send to Amplitude servers.
7-
* Note: price is the only required field. If quantity is not specified, then defaults to 1.
8-
*/
9-
105
/**
11-
* Revenue API - instance constructor. Revenue objects are a wrapper for revenue data.
6+
* Revenue API - instance constructor. Wrapper for logging Revenue data. Revenue objects get passed to amplitude.logRevenueV2 to send to Amplitude servers.
127
* Each method updates a revenue property in the Revenue object, and returns the same Revenue object,
138
* allowing you to chain multiple method calls together.
9+
*
1410
* Note: price is a required field to log revenue events.
1511
* If quantity is not specified then defaults to 1.
16-
* See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#tracking-revenue} for more information
17-
* about logging Revenue.
1812
* @constructor Revenue
1913
* @public
2014
* @example var revenue = new amplitude.Revenue();
@@ -68,7 +62,8 @@ Revenue.prototype.setQuantity = function setQuantity(quantity) {
6862

6963
/**
7064
* Set a value for the price. This field is required for all revenue being logged.
71-
* Note revenue amount is calculated as price * quantity.
65+
*
66+
* Note: revenue amount is calculated as price * quantity.
7267
* @public
7368
* @param {number} price - Double value for the quantity.
7469
* @return {Revenue} Returns the same Revenue object, allowing you to chain multiple method calls together.

website/generate-jsdoc.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,48 @@ function generateMarkdown(inputFile) {
2626
.join("\n");
2727
fs.writeFileSync(
2828
path.join(outputDir, `${className}.md`),
29-
prettier.format(markdownOutput, { parser: "markdown" })
29+
prettier.format(markdownOutput, { parser: "mdx" })
3030
);
3131
}
3232

3333
function documentItem(data) {
34-
return `## \`${data.id}\`
34+
return `${documentHeader(data)}
3535
3636
${data.examples ? documentExamples(data) : ""}
3737
3838
${data.description || ""}
3939
40+
${data.deprecated ? documentDeprecated(data) : ""}
41+
4042
${data.params ? documentParams(data) : ""}
4143
4244
${data.returns ? documentReturn(data) : ""}
4345
`;
4446
}
4547

48+
function documentHeader(data) {
49+
if (data.deprecated)
50+
return `## ~~\`${data.id}\`~~`
51+
return `## \`${data.id}\``
52+
}
53+
4654
function documentExamples(data) {
4755
return `\`\`\`
4856
${data.examples}
4957
\`\`\`
5058
`;
5159
}
5260

61+
function documentDeprecated(data) {
62+
return `:::danger Deprecated
63+
${data.deprecated}
64+
:::
65+
`;
66+
}
67+
5368
function documentParams(data) {
5469
const params = data.params.map(
55-
(param) => `- \`${param.name}\` (\`${param.type.names[0]}\`)
70+
(param) => `- \`${param.name}\` (\`${param.type.names.join('|')}\`)
5671
${param.description}
5772
`
5873
);
@@ -63,7 +78,7 @@ ${params.join("\n")}
6378

6479
function documentReturn(data) {
6580
return `### Return Value
66-
- (\`${data.returns[0].type.names[0]}\`)
81+
- (\`${data.returns[0].type.names.join('|')}\`)
6782
${data.returns[0].description}
6883
`;
6984
}

website/src/css/custom.css

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
--ifm-color-primary-light: #48a4de;
1515
--ifm-color-primary-lighter: #7bbee7;
1616
--ifm-color-primary-lightest: #c6e2f4;
17+
--ifm-color-danger: #E71829;
1718
--ifm-code-font-size: 95%;
1819
}
1920

@@ -23,32 +24,3 @@
2324
margin: 0 calc(-1 * var(--ifm-pre-padding));
2425
padding: 0 var(--ifm-pre-padding);
2526
}
26-
27-
/* OG site color #10069f */
28-
/* logo color #007fd2 */
29-
/* sidebar dark #003b61 */
30-
/* sidebar darkest #0c2a4b */
31-
/* Sidebar text ##c6d0d9 */
32-
33-
/* $cerulean-50: #f4faff;
34-
$cerulean-100: #e4f1fa;
35-
$cerulean-200: #c6e2f4;
36-
$cerulean-300: #7bbee7;
37-
$cerulean-400: #48a4de;
38-
$cerulean-500: #007fd2;
39-
$cerulean-600: #0065a5;
40-
$cerulean-700: #005488;
41-
$cerulean-800: #003b61;
42-
$cerulean-900: #0c2a4b;
43-
:export {
44-
cerulean-50: $cerulean-50;
45-
cerulean-100: $cerulean-100;
46-
cerulean-200: $cerulean-200;
47-
cerulean-300: $cerulean-300;
48-
cerulean-400: $cerulean-400;
49-
cerulean-500: $cerulean-500;
50-
cerulean-600: $cerulean-600;
51-
cerulean-700: $cerulean-700;
52-
cerulean-800: $cerulean-800;
53-
cerulean-900: $cerulean-900;
54-
} */

0 commit comments

Comments
 (0)