You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Analytics.js 2.0, the latest version of Segment's JavaScript source, enables you to send your data to any tool without having to learn, test, or use a new API every time.
12
12
13
-
> note ""
13
+
> info ""
14
14
> Analytics.js 2.0 is available as an [open-source project](https://github.com/segmentio/analytics-next/){:target="_blank"}.
15
+
> <br><br> All sources created on April 5, 2022 and after default to use Analytics.js 2.0.
<td>The database ID for the user. If you don't know who the user is yet, you can omit the `userId` and just record `traits`. You can read more about identities in the [identify reference](/docs/connections/spec/identify).</td>
79
-
</tr>
80
-
<tr>
81
-
<td>`traits`</td>
82
-
<td>optional</td>
83
-
<td>Object</td>
84
-
<td>A dictionary of traits you know about the user, like `email` or `name`. You can read more about traits in the [identify reference](/docs/connections/spec/identify/).</td>
85
-
</tr>
86
-
<tr>
87
-
<td>`options`</td>
88
-
<td>optional</td>
89
-
<td>Object</td>
90
-
<td>A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `traits` object, pass an empty object (as an '{}') before `options`_</td>
91
-
</tr>
92
-
<tr>
93
-
<td>`callback`</td>
94
-
<td>optional</td>
95
-
<td>Function</td>
96
-
<td>A function executed after a short timeout, giving the browser time to make outbound requests first.</td>
97
-
</tr>
98
-
</table>
99
-
74
+
Field | | Type | Description
75
+
----- | | ---- | -----------
76
+
`userId` | optional | String | The database ID for the user. If you don't know who the user is yet, you can omit the `userId` and just record `traits`. You can read more about identities in the [identify reference](/docs/connections/spec/identify).
77
+
`traits` | optional | Object | A dictionary of traits you know about the user, like `email` or `name`. You can read more about traits in the [identify reference](/docs/connections/spec/identify/).
78
+
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `traits` object, pass an empty object (as an '{}') before `options`._
79
+
`callback` | optional | Function | A function executed after a short timeout, giving the browser time to make outbound requests first.
100
80
101
81
By default, Analytics.js caches traits in the browser's `localStorage` and attaches them to each Identify call.
<td>The name of the event you're tracking. You can read more about the [track method](/docs/connections/spec/track) and recommended event names.</td>
150
-
</tr>
151
-
<tr>
152
-
<td>`properties`</td>
153
-
<td>optional</td>
154
-
<td>Object</td>
155
-
<td>A dictionary of [properties](/docs/connections/spec/track#properties) for the event. If the event was `'Added to Cart'`, it might have properties like `price` and `productType`.</td>
156
-
</tr>
157
-
<tr>
158
-
<td>`options`</td>
159
-
<td>optional</td>
160
-
<td>Object</td>
161
-
<td>A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before *options*_</td>
162
-
</tr>
163
-
<tr>
164
-
<td>`callback`</td>
165
-
<td>optional</td>
166
-
<td>Function</td>
167
-
<td>A function that runs after a short timeout, giving the browser time to make outbound requests first.</td>
168
-
</tr>
169
-
</table>
124
+
Field | | Type | Description
125
+
----- | | ---- | -----------
126
+
`event`| | String | The name of the event you're tracking. You can read more about the [track method](/docs/connections/spec/track) and recommended event names.
127
+
`properties` | optional | Object | A dictionary of [properties](/docs/connections/spec/track#properties) for the event. If the event was `'Added to Cart'`, it might have properties like `price` and `productType`.
128
+
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_.
129
+
`callback` | optional | Function | A function that runs after a short timeout, giving the browser time to make outbound requests first.
170
130
171
131
The only required argument in Analytics.js is an _event name string_. You can read more about [how Segment recommends you name events](/docs/connections/spec/track#event).
172
132
@@ -195,23 +155,11 @@ The `trackLink` method follows the format below.
195
155
analytics.trackLink(element, event, [properties])
196
156
```
197
157
198
-
<table>
199
-
<tr>
200
-
<td>`element(s)` </td>
201
-
<td>Element or Array</td>
202
-
<td>DOM element to bind with `track` method. You may pass an array of elements or jQuery objects. _Note: This must be an element, **not** a CSS selector._</td>
203
-
</tr>
204
-
<tr>
205
-
<td>`event` </td>
206
-
<td>String or Function</td>
207
-
<td>The name of the event, passed to the `track` method. Or a **function** that returns a string to use as the name of the `track` event.</td>
208
-
</tr>
209
-
<tr>
210
-
<td>`properties` optional</td>
211
-
<td>Object or Function</td>
212
-
<td>A dictionary of properties to pass with the track method or a **function** that returns an object to use as the `properties` of the event.</td>
213
-
</tr>
214
-
</table>
158
+
Field | | Type | Description
159
+
----- | | ---- | -----------
160
+
`element(s)` | | Element or Array | DOM element to bind with `track` method. You may pass an array of elements or jQuery objects. _Note: This must be an element, **not** a CSS selector._
161
+
`event` | | String or Function | The name of the event, passed to the `track` method. Or a **function** that returns a string to use as the name of the `track` event.
162
+
`properties` | optional | Object or Function | A dictionary of properties to pass with the track method or a **function** that returns an object to use as the `properties` of the event.
215
163
216
164
Example:
217
165
@@ -234,23 +182,12 @@ The `trackForm` method follows the format below.
234
182
analytics.trackForm(form, event, [properties])
235
183
```
236
184
237
-
<table>
238
-
<tr>
239
-
<td>`form(s)` Element or Array</td>
240
-
<td>Element or Array</td>
241
-
<td>The form element to track or an array of form elements or jQuery objects. _Note: trackForm takes an element, not a CSS selector._</td>
242
-
</tr>
243
-
<tr>
244
-
<td>`event` </td>
245
-
<td>String or Function</td>
246
-
<td>The name of the event, passed to the `track` method. Or a **function** that returns a string to use as the name of the `track` event.</td>
247
-
</tr>
248
-
<tr>
249
-
<td>`properties` optional</td>
250
-
<td>Object or Function</td>
251
-
<td>A dictionary of properties to pass with the track method. Or a **function** that returns an object to use as the `properties` of the event.</td>
252
-
</tr>
253
-
</table>
185
+
Field | | Type | Description
186
+
----- | | ---- | -----------
187
+
`form(s)` | | Element or Array | The form element to track or an array of form elements or jQuery objects. _Note: trackForm takes an element, not a CSS selector._
188
+
`event` | | Element or Array | The form element to track or an array of form elements or jQuery objects. _Note: trackForm takes an element, not a CSS selector._
189
+
`form(s)` | | Element or Array | The form element to track or an array of form elements or jQuery objects. _Note: trackForm takes an element, not a CSS selector._
190
+
`properties` | optional | Object or Function | A dictionary of properties to pass with the track method. Or a **function** that returns an object to use as the `properties` of the event.
<td>The category of the page. Useful for cases like ecommerce where many pages might live under a single category. _Note: if you pass only one string to `page` it is assumed to be `name`. You **must** include a `name` to send a `category`._</td>
288
-
</tr>
289
-
<tr>
290
-
<td>`name`</td>
291
-
<td>optional</td>
292
-
<td> String</td>
293
-
<td>The name of the page.</td>
294
-
</tr>
295
-
<tr>
296
-
<td>`properties`</td>
297
-
<td>optional</td>
298
-
<td> Object </td>
299
-
<td>A dictionary of properties of the page. Note: Analytics.js collects `url`, `title`, `referrer` and `path` are automatically. This defaults to a `canonical url`, if available, and falls back to `document.location.href`.</td>
300
-
</tr>
301
-
<tr>
302
-
<td>`options`</td>
303
-
<td>optional</td>
304
-
<td>Object</td>
305
-
<td>A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_ </td>
306
-
</tr>
307
-
<tr>
308
-
<td>`callback`</td>
309
-
<td>optional</td>
310
-
<td>Function</td>
311
-
<td>A function that runs after a short timeout, giving the browser time to make outbound requests first.</td>
312
-
</tr>
313
-
</table>
314
-
219
+
Field | | Type | Description
220
+
----- | | ---- | -----------
221
+
`category` | optional | String | The category of the page. Useful for cases like ecommerce where many pages might live under a single category. _Note: if you pass only one string to `page` it is assumed to be `name`. You **must** include a `name` to send a `category`._
222
+
`name` | optional | String | The name of the page.
223
+
`properties` | optional | Object | A dictionary of properties of the page. Note: Analytics.js collects `url`, `title`, `referrer` and `path` are automatically. This defaults to a `canonical url`, if available, and falls back to `document.location.href`.
224
+
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_.
225
+
`callback` | optional | Function | A function that runs after a short timeout, giving the browser time to make outbound requests first.
<td>The Group ID to associate with the current user.</td>
374
-
</tr>
375
-
<tr>
376
-
<td>`traits`</td>
377
-
<td>optional</td>
378
-
<td> Object</td>
379
-
<td>A dictionary of [traits](/docs/connections/spec/group#traits) for the group. Example traits for a group include `address`, `website`, and `employees`.</td>
380
-
</tr>
381
-
<tr>
382
-
<td>`options`</td>
383
-
<td>optional</td>
384
-
<td>Object</td>
385
-
<td>A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_</td>
386
-
</tr>
387
-
<tr>
388
-
<td>`callback`</td>
389
-
<td>optional</td>
390
-
<td>Function</td>
391
-
<td>A function that runs after a short timeout, giving the browser time to make outbound requests first.</td>
392
-
</tr>
393
-
</table>
394
-
279
+
Field | | Type | Description
280
+
----- | | ---- | -----------
281
+
`groupId` | | String | The Group ID to associate with the current user.
282
+
`traits` | optional | Object | A dictionary of [traits](/docs/connections/spec/group#traits) for the group. Example traits for a group include `address`, `website`, and `employees`.
283
+
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_.
284
+
`callback` | optional | Function | A function that runs after a short timeout, giving the browser time to make outbound requests first.
<td>The new user ID you want to associate with the user.</td>
431
-
</tr>
432
-
<tr>
433
-
<td>`previousId`</td>
434
-
<td>optional</td>
435
-
<td>String</td>
436
-
<td>The previous ID that the user was recognized by. This defaults to the currently identified user's ID.</td>
437
-
</tr>
438
-
<tr>
439
-
<td>`options`</td>
440
-
<td>optional</td>
441
-
<td>Object</td>
442
-
<td>A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call.</td>
443
-
</tr>
444
-
<tr>
445
-
<td>`callback`</td>
446
-
<td>optional</td>
447
-
<td>Function</td>
448
-
<td>A function that is executed after a short timeout, giving the browser time to make outbound requests first.</td>
449
-
</tr>
450
-
</table>
315
+
Field | | Type | Description
316
+
----- | | ---- | -----------
317
+
`userId` | | String | The new user ID you want to associate with the user.
318
+
`previousId` | optional | String | The previous ID that the user was recognized by. This defaults to the currently identified user's ID.
319
+
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call.
320
+
`callback` | optional | Function | A function that is executed after a short timeout, giving the browser time to make outbound requests first.
451
321
452
322
For more details about Alias, including the **`alias` call payload**, check out our [Spec](/docs/connections/spec/alias/).
453
323
@@ -487,13 +357,9 @@ analytics.ready(callback);
487
357
488
358
The `ready` method has the following fields:
489
359
490
-
<table>
491
-
<tr>
492
-
<td>`callback` </td>
493
-
<td>Function</td>
494
-
<td>A function to be executed after all enabled destinations have loaded.</td>
495
-
</tr>
496
-
</table>
360
+
Field | Type | Description
361
+
----- | ---- | -----------
362
+
`callback` | Function | A function to be executed after all enabled destinations have loaded.
497
363
498
364
### Debug
499
365
@@ -520,18 +386,10 @@ Use the `on` method to set listeners for these events and run your own custom co
520
386
analytics.on(method, callback);
521
387
```
522
388
523
-
<table>
524
-
<tr>
525
-
<td>`method` </td>
526
-
<td>String</td>
527
-
<td>Name of the method to listen for</td>
528
-
</tr>
529
-
<tr>
530
-
<td>`callback` </td>
531
-
<td>Function</td>
532
-
<td>A function to execute after each emitted method, taking three arguments: `event`, `properties`, `options`</td>
533
-
</tr>
534
-
</table>
389
+
Field | Type | Description
390
+
----- | ---- | -----------
391
+
`method` | String | Name of the method to listen for.
392
+
`callback`| Function | A function to execute after each emitted method, taking three arguments: `event`, `properties`, `options`.
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/website/javascript/upgrade-to-ajs2.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Analytics.js sources will upgrade to Analytics.js 2.0 on the date below, accordi
31
31
|--------------| -------------|
32
32
| Free | June 15, 2021|
33
33
| Team | July 6, 2021 |
34
-
| Business |TBD |
34
+
| Business |June 2022|
35
35
36
36
> info ""
37
37
> The plans and dates listed above are subject to change.
@@ -46,7 +46,11 @@ In some cases, upgrading to Analytics.js 2.0 requires manual effort beyond enabl
46
46
47
47
### Using in-domain instrumentation CDN aliasing
48
48
49
-
If the source you intend to upgrade uses the in-domain instrumentation as well as a custom "Alias for analytics.js", then you should update the AJS snippet to the latest version (4.15.3 or higher) before you toggle on Analytics.js 2.0.
49
+
If the source you intend to upgrade uses the in-domain instrumentation as well as a custom "Alias for analytics.js", then you should update the Analytics.js snippet to the latest version (4.15.3 or higher) before you toggle on Analytics.js 2.0.
50
+
51
+
### Using a mix of Analytics.js Classic and 2.0 sources
52
+
53
+
If you're using a mix of Analytics.js Classic and 2.0 sources, the classic source won't be able to use the anonymous ID set by Analytics.js 2.0. In order to fix this, update all sources to 2.0.
50
54
51
55
### Relying on Analytics.js Classic's `ajs_anonymous_id` cookie format
0 commit comments