Skip to content

Commit 48e45c7

Browse files
committed
update from master
2 parents 9aec943 + f750cc5 commit 48e45c7

File tree

8 files changed

+94
-59
lines changed

8 files changed

+94
-59
lines changed

README.md

Lines changed: 87 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@ Amplitude-Javascript
77
1. If you haven't already, go to http://amplitude.com and register for an account. You will receive an API Key.
88
2. On every page that uses analytics, paste the following Javascript code between the `<head>` and `</head>` tags:
99

10-
<script type="text/javascript">
11-
(function(t,e){var n=t.amplitude||{};var r=e.createElement("script");r.type="text/javascript";
12-
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.5.0-min.gz.js";
13-
r.onload=function(){t.amplitude.runQueuedFunctions()};var s=e.getElementsByTagName("script")[0];
14-
s.parentNode.insertBefore(r,s);var i=function(){this._q=[];return this};function o(t){
15-
i.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
16-
return this}}var a=["add","set","setOnce","unset"];for(var u=0;u<a.length;u++){o(a[u]);
17-
}n.Identify=i;n._q=[];function c(t){n[t]=function(){n._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
18-
}}var l=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify"];
19-
for(var p=0;p<l.length;p++){c(l[p])}t.amplitude=n})(window,document);
20-
21-
amplitude.init("YOUR_API_KEY_HERE");
22-
</script>
10+
```
11+
<script type="text/javascript">
12+
(function(t,e){var n=t.amplitude||{};var r=e.createElement("script");r.type="text/javascript";
13+
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.6.0-min.gz.js";
14+
r.onload=function(){t.amplitude.runQueuedFunctions()};var s=e.getElementsByTagName("script")[0];
15+
s.parentNode.insertBefore(r,s);var i=function(){this._q=[];return this};function o(t){
16+
i.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
17+
return this}}var a=["add","set","setOnce","unset"];for(var u=0;u<a.length;u++){o(a[u]);
18+
}n.Identify=i;n._q=[];function c(t){n[t]=function(){n._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
19+
}}var l=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify"];
20+
for(var p=0;p<l.length;p++){c(l[p])}t.amplitude=n})(window,document);
21+
22+
amplitude.init("YOUR_API_KEY_HERE");
23+
</script>
24+
```
2325

2426
3. Replace `YOUR_API_KEY_HERE` with the API Key given to you.
2527
4. To track an event anywhere on the page, call:
2628

27-
amplitude.logEvent("EVENT_IDENTIFIER_HERE");
29+
```javascript
30+
amplitude.logEvent('EVENT_IDENTIFIER_HERE');
31+
```
2832

2933
5. Events are uploaded immediately and saved to the browser's local storage until the server confirms the upload. After calling logEvent in your app, you will immediately see data appear on Amplitude.
3034

@@ -36,33 +40,31 @@ It's important to think about what types of events you care about as a developer
3640

3741
If your app has its own login system that you want to track users with, you can call `setUserId` at any time:
3842

39-
amplitude.setUserId("USER_ID_HERE");
43+
```javascript
44+
amplitude.setUserId('USER_ID_HERE');
45+
```
4046

4147
A user's data will be merged on the backend so that any events up to that point from the same browser will be tracked under the same user.
4248

4349
You can also add the user ID as an argument to the `init` call:
4450

45-
amplitude.init("YOUR_API_KEY_HERE", "USER_ID_HERE");
51+
```javascript
52+
amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE');
53+
```
4654

4755
# Setting Event Properties #
4856

4957
You can attach additional data to any event by passing a Javascript object as the second argument to `logEvent`:
5058

51-
var eventProperties = {};
52-
eventProperties.key = "value";
53-
amplitude.logEvent("EVENT_IDENTIFIER_HERE", eventProperties);
54-
55-
# Setting User Properties #
56-
57-
To add properties that are tracked in every event, you can set properties for a user:
58-
59-
var userProperties = {};
60-
userProperties.key = "value";
61-
amplitude.setUserProperties(userProperties);
59+
```javascript
60+
var eventProperties = {};
61+
eventProperties.key = 'value';
62+
amplitude.logEvent('EVENT_IDENTIFIER_HERE', eventProperties);
63+
```
6264

6365
# User Property Operations #
6466

65-
The SDK supports the operations set, setOnce, unset, and add on individual user properties. The operations are declared via a provided `Identify` interface. Multiple operations can be chained together in a single `Identify` object. The `Identify` object is then passed to the Amplitude client to send to the server. The results of the operations will be visible immediately in the dashboard, and take effect for events logged after.
67+
The SDK supports the operations `set`, `setOnce`, `unset`, and `add` on individual user properties. The operations are declared via a provided `Identify` interface. Multiple operations can be chained together in a single `Identify` object. The `Identify` object is then passed to the Amplitude client to send to the server. The results of the operations will be visible immediately in the dashboard, and take effect for events logged after.
6668

6769
1. `set`: this sets the value of a user property.
6870

@@ -98,15 +100,32 @@ The SDK supports the operations set, setOnce, unset, and add on individual user
98100
Note: if a user property is used in multiple operations on the same `Identify` object, only the first operation will be saved, and the rest will be ignored. In this example, only the set operation will be saved, and the add and unset will be ignored:
99101

100102
```javascript
101-
var identify = new amplitude.Identify().set('karma', 10).add('karma', 1).unset('karma');
103+
var identify = new amplitude.Identify()
104+
.set('karma', 10)
105+
.add('karma', 1)
106+
.unset('karma');
102107
amplitude.identify(identify);
103108
```
104109

110+
### Setting Multiple Properties with `setUserProperties` ###
111+
112+
You may use `setUserProperties` shorthand to set multiple user properties at once. This method is simply a wrapper around `Identify.set` and `identify`.
113+
114+
```javascript
115+
var userProperties = {
116+
gender: 'female',
117+
age: 20
118+
};
119+
amplitude.setUserProperties(userProperties);
120+
```
121+
105122
# Tracking Revenue #
106123

107124
To track revenue from a user, call
108125

109-
amplitude.logRevenue(9.99, 1, "product");
126+
```javascript
127+
amplitude.logRevenue(9.99, 1, 'product');
128+
```
110129

111130
The function takes a unit price, a quantity, and a product identifier. Quantity and product identifier are optional parameters.
112131

@@ -116,27 +135,33 @@ This allows us to automatically display data relevant to revenue on the Amplitud
116135

117136
You can turn off logging for a given user:
118137

119-
amplitude.setOptOut(true);
138+
```javascript
139+
amplitude.setOptOut(true);
140+
```
120141

121142
No events will be saved or sent to the server while opt out is enabled. The opt out
122143
setting will persist across page loads. Calling
123144

124-
setOptOut(false)
145+
```javascript
146+
amplitude.setOptOut(false);
147+
```
125148

126149
will reenable logging.
127150

128151
# Configuration Options #
129152

130153
You can configure Amplitude by passing an object as the third argument to the `init`:
131154

132-
amplitude.init("YOUR_API_KEY_HERE", null, {
133-
// optional configuration options
134-
saveEvents: true,
135-
includeUtm: true,
136-
includeReferrer: true,
137-
batchEvents: true,
138-
eventUploadThreshold: 50
139-
})
155+
```javascript
156+
amplitude.init('YOUR_API_KEY_HERE', null, {
157+
// optional configuration options
158+
saveEvents: true,
159+
includeUtm: true,
160+
includeReferrer: true,
161+
batchEvents: true,
162+
eventUploadThreshold: 50
163+
});
164+
```
140165

141166
| option | description | default |
142167
|------------|----------------------------------------------------------------------------------|-----------|
@@ -157,44 +182,54 @@ This SDK automatically grabs useful data about the browser, including browser ty
157182

158183
By default, no version name is set. You can specify a version name to distinguish between different versions of your site by calling `setVersionName`:
159184

160-
amplitude.setVersionName("VERSION_NAME_HERE");
185+
```javascript
186+
amplitude.setVersionName('VERSION_NAME_HERE');
187+
```
161188

162189
User IDs are automatically generated and stored in cookies if not specified.
163190

164191
Device IDs are generated randomly, although you can define a custom device ID setting it as a configuration option or by calling:
165192

166-
amplitude.setDeviceId("CUSTOM_DEVICE_ID");
193+
```javascript
194+
amplitude.setDeviceId('CUSTOM_DEVICE_ID');
195+
```
167196

168197
You can pass a callback function to logEvent, which will get called after receiving a response from the server:
169198

170-
amplitude.logEvent("EVENT_IDENTIFIER_HERE", null, callback_function);
199+
```javascript
200+
amplitude.logEvent("EVENT_IDENTIFIER_HERE", null, callback_function);
201+
```
171202

172203
The status and response from the server are passed to the callback function, which you might find useful. An example of a callback function which redirects the browser to another site after a response:
173204

174205
```javascript
175-
var callback_function = function(status, response) {
206+
var callback_function = function(status, response) {
176207
if (status === 200 && response === 'success') {
177-
// do something here
208+
// do something here
178209
}
179210
window.location.replace('URL_OF_OTHER_SITE');
180-
};
211+
};
181212
```
182213

183214
You can also use this to track outbound links on your website. For example you would have a link like this:
184215

185-
<a href="javascript:trackClickLinkA();">Link A</a>
216+
```html
217+
<a href="javascript:trackClickLinkA();">Link A</a>
218+
```
186219

187220
And then you would define a function that is called when the link is clicked like this:
188221

189222
```javascript
190223
var trackClickLinkA = function() {
191-
amplitude.logEvent('Clicked Link A', null, function() {
192-
window.location="LINK_A_URL";
193-
});
194-
}
224+
amplitude.logEvent('Clicked Link A', null, function() {
225+
window.location='LINK_A_URL';
226+
});
227+
};
195228
```
196229
You can also pass a callback function to init, which will get called after the SDK finishes its asynchronous loading. Note: no values are passed to the init callback function:
197230

198-
amplitude.init("YOUR_API_KEY_HERE", "USER_ID_HERE", null, callback_function);
231+
```javascript
232+
amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE', null, callback_function);
233+
```
199234

200235
In the case that `optOut` is true, then no event will be logged, but the callback will be called. In the case that `batchEvents` is true, if the batch requirements `eventUploadThreshold` and `eventUploadPeriodMillis` are not met when `logEvent` is called, then no request is sent, but the callback is still called. In these cases, the callback will be called with an input status of 0 and response 'No request sent'.

amplitude-snippet.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(t,e){var n=t.amplitude||{};var r=e.createElement("script");r.type="text/javascript";
2-
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.5.0-min.gz.js";
2+
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.6.0-min.gz.js";
33
r.onload=function(){t.amplitude.runQueuedFunctions()};var s=e.getElementsByTagName("script")[0];
44
s.parentNode.insertBefore(r,s);var i=function(){this._q=[];return this};function o(t){
55
i.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));

amplitude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,7 @@ module.exports = uuid;
33313331

33323332
}, {}],
33333333
12: [function(require, module, exports) {
3334-
module.exports = '2.5.0';
3334+
module.exports = '2.6.0';
33353335

33363336
}, {}],
33373337
13: [function(require, module, exports) {

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"main": "src/index.js",
44
"repo": "amplitude/amplitude-javascript",
55
"description": "Javascript library for Amplitude Analytics",
6-
"version": "2.5.0",
6+
"version": "2.6.0",
77
"keywords": [
88
"analytics",
99
"amplitude"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "amplitude-js",
33
"author": "Amplitude <[email protected]>",
4-
"version": "2.5.0",
4+
"version": "2.6.0",
55
"license": "MIT",
66
"description": "Javascript library for Amplitude Analytics",
77
"keywords": [

src/amplitude-snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var as = document.createElement('script');
44
as.type = 'text/javascript';
55
as.async = true;
6-
as.src = 'https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.5.0-min.gz.js';
6+
as.src = 'https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.6.0-min.gz.js';
77
as.onload = function() { window.amplitude.runQueuedFunctions(); };
88
var s = document.getElementsByTagName('script')[0];
99
s.parentNode.insertBefore(as, s);

src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = '2.5.0';
1+
module.exports = '2.6.0';

0 commit comments

Comments
 (0)