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
- Obtains a cached value for the provided `key`, invoking the callback if the value is missing or has expired. The `ttl` is the maximum duration in milliseconds the value can be cached. If omitted or set to `-1`, the value will have no expiry. There is no guarantee that a value will be retained in the cache for the provided duration, however. The cache space is limited, so efforts to minimize the cached value size will afford a higher cache hit ratio.
37
+
- Obtains a cached value for the provided `key`, invoking the callback if the value is missing or has expired. The `ttl` is the maximum duration in milliseconds the value can be cached. If omitted or set to `-1`, the value will have no expiry.
38
38
-`cache.delete(key: string): void`
39
-
-Forcefully remove the value associated with the `key`.
39
+
-Immediately remove the value associated with the `key`.
40
40
41
+
Some important notes about the cache:
42
+
43
+
- When testing functions in the code editor, the cache will be empty because each test temporarily deploys a new instance of the function.
44
+
- Values in the cache are not shared between concurrently-running function instances; they are process-local which means that high-volume functions will have many separate caches.
45
+
- Values may be expunged at any time, even before the configured TTL is reached. This can happen due to memory pressure or normal scaling activity. Minimizing the size of cached values can improve your hit/miss ratio.
46
+
- Functions that receive a low volume of traffic may be temporarily suspended, during which their caches will be emptied. In general, caches are best used for high-volume functions and with long TTLs.
41
47
The following example gets a JSON value through the cache, only invoking the callback as needed:
Copy file name to clipboardExpand all lines: src/connections/destinations/catalog/actions-amplitude/index.md
+3
Original file line number
Diff line number
Diff line change
@@ -170,6 +170,9 @@ When you send an "Order Completed" event from Segment, an "Order Completed" even
170
170
171
171
#### Track Revenue Per Product
172
172
173
+
> info ""
174
+
> If you use Track Revenue Per Product, add a `revenue` property inside the `products` array of the Order Completed event.
175
+
173
176
Amplitude has two different ways to track revenue associated with a multi-product purchase. You can choose which method you want to use using the **Track Revenue Per Product** destination setting.
174
177
175
178
If you disable the setting ("off"), Segment sends a single revenue event with the total amount purchased and adds revenue data the Amplitude "Order Completed" event. The "Product Purchased" events do not contain any native Amplitude revenue data.
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/website/javascript/index.md
+130-2
Original file line number
Diff line number
Diff line change
@@ -501,7 +501,7 @@ Calling the `debug` method turns on debug mode, which logs helpful messages to t
501
501
502
502
Enable:
503
503
```js
504
-
analytics.debug();
504
+
analytics.debug(true);
505
505
```
506
506
507
507
Disable:
@@ -721,7 +721,135 @@ No, there is no change in behavior to Middlewares.
721
721
#### When using Segment features (Schema filtering, integrations object, Protocols) to filter events from going to destinations (device and cloud-mode), will batching impact the filtering of events?
722
722
No, there is no impact to how events filter.
723
723
724
-
## Plugins
724
+
## Plugin Architecture
725
+
When you develop against Analytics 2.0, the plugins you write can augment functionality, enrich data, and control the flow and delivery of events. From modifying event payloads to changing analytics functionality, plugins help to speed up the process of getting things done.
726
+
727
+
Though middlewares function the same as plugins, it's best to use plugins as they are easier to implement and are more testable.
728
+
729
+
### Plugin Categories
730
+
Plugins are bound by Analytics 2.0 which handles operations such as observability, retries, and error handling. There are two different categories of plugins:
731
+
***Critical Plugins**: Analytics.js expects this plugin to be loaded before starting event delivery. Failure to load a critical plugin halts event delivery. Use this category sparingly, and only for plugins that are critical to your tracking.
732
+
***Non-critical Plugins**: Analytics.js can start event delivery before this plugin finishes loading. This means your plugin can fail to load independently from all other plugins. For example, every Analytics.js destination is a non-critical plugin. This makes it possible for Analytics.js to continue working if a partner destination fails to load, or if users have ad blockers turned on that are targeting specific destinations.
733
+
734
+
> info ""
735
+
> Non-critical plugins are only non-critical from a loading standpoint. For example, if the `before` plugin crashes, this can still halt the event delivery pipeline.
736
+
737
+
Non-critical plugins run through a timeline that executes in order of insertion based on the entry type. Segment has these five entry types of non-critical plugins:
738
+
739
+
Type | Details
740
+
---- | -------
741
+
`before` | Executes before event processing begins. These are plugins that run before any other plugins run. <br><br>For example, validating events before passing them along to other plugins. A failure here could halt the event pipeline. <br><br> See the example of how Analytics.js uses the [Event Validation plugin](https://github.com/segmentio/analytics-next/blob/master/src/plugins/validation/index.ts){:target="_blank"} to verify that every event has the correct shape.
742
+
`enrichment` | Executes as the first level of event processing. These plugins modify an event. <br><br> See the example of how Analytics.js uses the [Page Enrichment plugin](https://github.com/segmentio/analytics-next/blob/master/src/plugins/page-enrichment/index.ts){:target="_blank"} to enrich every event with page information.
743
+
`destination` | Executes as events begin to pass off to destinations. <br><br> This doesn’t modify the event outside of the specific destination, and failure doesn’t halt the execution.
744
+
`after` | Executes after all event processing completes. You can use this to perform cleanup operations. <br><br>An example of this is the [Segment.io Plugin](https://github.com/segmentio/analytics-next/blob/master/src/plugins/segmentio/index.ts){:target="_blank"} which waits for destinations to succeed or fail so it can send it observability metrics.
745
+
`utility` | Executes once during the bootstrap, to give you an outlet to make any modifications as to how Analytics.js works internally. This allows you to augment Analytics.js functionality.
746
+
747
+
### Example Plugins
748
+
Here's an example of a plugin that converts all track event names to lowercase before the event goes through the rest of the pipeline:
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/website/javascript/upgrade-to-ajs2.md
+11-9
Original file line number
Diff line number
Diff line change
@@ -16,39 +16,41 @@ To upgrade a source to Analytics.js 2.0:
16
16
5. Within 5 minutes, the source receives Analytics.js 2.0. No code or tag changes required.
17
17
6. Open the Debugger to ensure that events are flowing as expected.
18
18
19
+
> info ""
20
+
> If you set `'Segment.io:' false' in the integrations object, Analytics.js 2.0 drops the event before it reaches the Source Debugger.
21
+
19
22
## Automatic migration
20
23
21
24
Analytics.js sources will upgrade to Analytics.js 2.0 on the date below, according to the account tier. On the date listed, Segment will upgrade all Analytics.js sources within the associated account tier.
22
25
23
26
| Segment Plan | Upgrade Date |
24
27
|--------------| -------------|
25
28
| Free | June 15, 2021|
26
-
| Team | July 6, 2021 |
29
+
| Team | July 6, 2021 |
27
30
| Business | TBD |
28
31
29
32
> info ""
30
33
> The plans and dates listed above are subject to change.
31
34
32
35
## Revert to Analytics.js Classic
33
36
34
-
Once a source moves to Analytics.js 2.0, you can follow the steps above in [Manual migration](#manual-migration) back to roll back to Analytics.js Classic.
37
+
Once a source moves to Analytics.js 2.0, you can follow the steps above in [Manual migration](#manual-migration) back to roll back to Analytics.js Classic.
35
38
36
39
## Cases that require additional intervention
37
40
38
41
In some cases, upgrading to Analytics.js 2.0 requires manual effort beyond enabling the Analytics.js 2.0 toggle.
39
42
40
-
### When using in-domain instrumentation CDN aliasing
41
-
42
-
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.
43
+
### Using in-domain instrumentation CDN aliasing
43
44
45
+
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.
44
46
45
-
### When relying on Analytics.js Classic's `ajs_anonymous_id` cookie format
47
+
### Relying on Analytics.js Classic's `ajs_anonymous_id` cookie format
46
48
47
49
Analytics.js 2.0 removes inbuilt quotes from cookie values, resulting in a different format for the `ajs_anonymous_id` value when compared to Analytics.js Classic. Though you can retrieve cookie values with [standard supported functions](/docs/connections/sources/catalog/libraries/website/javascript/identity/#retrieve-the-anonymous-id), you'll need to configure your environment to accept the new format if your implementation relies on accessing the cookie value directly.
48
50
49
-
### When using a strict content security policy on the page
51
+
### Using a strict content security policy on the page
50
52
51
-
Analytics.js 2.0 asynchronously loads different pieces of the library as needed. If the source you're upgrading uses a strict Content Security Policy (CSP) that allows JavaScript to be downloaded from specific locations, then you need to update the CSP to account for all the pieces used for Analytics.js 2.0. Therefore, beyond allowing the main analytics.min.js script, you should allow the following paths in your CSP:
53
+
Analytics.js 2.0 asynchronously loads different pieces of the library as needed. If the source you're upgrading uses a strict Content Security Policy (CSP) that allows JavaScript to be downloaded from specific locations, then you need to update the CSP to account for all the pieces used for Analytics.js 2.0. Therefore, beyond allowing the main analytics.min.js script, you should allow the following paths in your CSP:
Copy file name to clipboardExpand all lines: src/connections/storage/catalog/amazon-s3/index.md
+3
Original file line number
Diff line number
Diff line change
@@ -166,6 +166,9 @@ Segment recommends doing this as a best practice. The following policy strictly
166
166
167
167
## Region
168
168
169
+
> warning ""
170
+
> The Amazon S3 destination only supports workspaces in the US region. Workspaces outside of the US can't connect to this destination. If you wish to connect to a different region use Segment's new [AWS S3 destination](https://segment.com/docs/connections/storage/catalog/aws-s3/) instead.
171
+
169
172
Segment infers the region of your bucket when data is copied to it, so you don't need to specify a bucket region in your configuration. If you're using VPC Endpoints for your S3 bucket, make sure you configure the endpoint in the same region as your bucket. You can find more information on this in the AWS S3 docs [here](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-endpoints-s3.html).
0 commit comments