Skip to content

Commit 09446c6

Browse files
authored
Merge pull request #299 from segmentio/repo-sync
repo sync
2 parents 6d9d757 + 5692a68 commit 09446c6

File tree

2 files changed

+57
-195
lines changed

2 files changed

+57
-195
lines changed

src/connections/sources/catalog/libraries/website/javascript/index.md

Lines changed: 51 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ id: IqDTy1TpoU
1010
---
1111
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.
1212

13-
> note ""
13+
> info ""
1414
> 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.
1516
1617

1718
## Benefits of Analytics.js 2.0
@@ -70,33 +71,12 @@ analytics.identify([userId], [traits], [options], [callback]);
7071

7172
The Identify call has the following fields:
7273

73-
<table>
74-
<tr>
75-
<td>`userId`</td>
76-
<td>optional</td>
77-
<td>String</td>
78-
<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.
10080

10181
By default, Analytics.js caches traits in the browser's `localStorage` and attaches them to each Identify call.
10282

@@ -141,32 +121,12 @@ analytics.track(event, [properties], [options], [callback]);
141121

142122
The `track` call has the following fields:
143123

144-
<table>
145-
<tr>
146-
<td>`event`</td>
147-
<td></td>
148-
<td>String</td>
149-
<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.
170130

171131
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).
172132

@@ -195,23 +155,11 @@ The `trackLink` method follows the format below.
195155
analytics.trackLink(element, event, [properties])
196156
```
197157

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.
215163

216164
Example:
217165

@@ -234,23 +182,12 @@ The `trackForm` method follows the format below.
234182
analytics.trackForm(form, event, [properties])
235183
```
236184

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.
254191

255192
Example:
256193

@@ -279,39 +216,13 @@ analytics.page([category], [name], [properties], [options], [callback]);
279216

280217
The `page` call has the following fields:
281218

282-
<table>
283-
<tr>
284-
<td>`category`</td>
285-
<td>optional</td>
286-
<td>String</td>
287-
<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.
315226

316227
#### Default Page Properties
317228

@@ -365,33 +276,12 @@ analytics.group(groupId, [traits], [options], [callback]);
365276
```
366277
The Group call has the following fields:
367278

368-
<table>
369-
<tr>
370-
<td>`groupId`</td>
371-
<td></td>
372-
<td>String</td>
373-
<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.
395285

396286
Example `group` call:
397287

@@ -422,32 +312,12 @@ analytics.alias(userId, [previousId], [options], [callback]);
422312

423313
The Alias call has the following fields:
424314

425-
<table>
426-
<tr>
427-
<td>`userId`</td>
428-
<td></td>
429-
<td>String</td>
430-
<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.
451321

452322
For more details about Alias, including the **`alias` call payload**, check out our [Spec](/docs/connections/spec/alias/).
453323

@@ -487,13 +357,9 @@ analytics.ready(callback);
487357

488358
The `ready` method has the following fields:
489359

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.
497363

498364
### Debug
499365

@@ -520,18 +386,10 @@ Use the `on` method to set listeners for these events and run your own custom co
520386
analytics.on(method, callback);
521387
```
522388

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`.
535393

536394
Example:
537395

src/connections/sources/catalog/libraries/website/javascript/upgrade-to-ajs2.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Analytics.js sources will upgrade to Analytics.js 2.0 on the date below, accordi
3131
|--------------| -------------|
3232
| Free | June 15, 2021|
3333
| Team | July 6, 2021 |
34-
| Business | TBD |
34+
| Business | June 2022 |
3535

3636
> info ""
3737
> 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
4646

4747
### Using in-domain instrumentation CDN aliasing
4848

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.
5054

5155
### Relying on Analytics.js Classic's `ajs_anonymous_id` cookie format
5256

0 commit comments

Comments
 (0)