Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a283ebc

Browse files
authored
Merge pull request segmentio#2065 from segmentio/develop
Release 21.43.1
2 parents cec49f7 + 4b38e60 commit a283ebc

File tree

9 files changed

+172
-34
lines changed

9 files changed

+172
-34
lines changed

Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
source "https://rubygems.org"
22

33
gem "jekyll", github: "jekyll/jekyll"
4-
gem "liquid-c"
54

65
group :development do
76
gem "faraday"

Gemfile.lock

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: https://github.com/jekyll/jekyll.git
3-
revision: 5687bf97d8242feb8bb8f03cdc93991fb20847b7
3+
revision: 26a949df85a1f9577e8080e19f2196c8a3db17ec
44
specs:
55
jekyll (4.2.1)
66
addressable (~> 2.4)
@@ -92,14 +92,12 @@ GEM
9292
jekyll (>= 3.7, < 5.0)
9393
jekyll-watch (2.2.1)
9494
listen (~> 3.0)
95-
json (2.5.1)
95+
json (2.6.0)
9696
kramdown (2.3.1)
9797
rexml
9898
kramdown-parser-gfm (1.1.0)
9999
kramdown (~> 2.0)
100100
liquid (4.0.3)
101-
liquid-c (4.0.0)
102-
liquid (>= 3.0.0)
103101
listen (3.7.0)
104102
rb-fsevent (~> 0.10, >= 0.10.3)
105103
rb-inotify (~> 0.9, >= 0.9.10)
@@ -115,7 +113,7 @@ GEM
115113
premonition (2.0.1)
116114
progressbar (1.11.0)
117115
public_suffix (4.0.6)
118-
racc (1.5.2)
116+
racc (1.6.0)
119117
rake (13.0.6)
120118
rb-fsevent (0.11.0)
121119
rb-inotify (0.10.1)
@@ -131,7 +129,7 @@ GEM
131129
thread_safe (0.3.6)
132130
tzinfo (1.2.9)
133131
thread_safe (~> 0.1)
134-
tzinfo-data (1.2021.2)
132+
tzinfo-data (1.2021.4)
135133
tzinfo (>= 1.0.0)
136134
unicode-display_width (2.1.0)
137135
verbal_expressions (0.1.5)
@@ -154,7 +152,6 @@ DEPENDENCIES
154152
jekyll-last-modified-at
155153
jekyll-redirect-from
156154
jekyll-sitemap
157-
liquid-c
158155
premonition (~> 2.0.0)
159156
rake
160157
tzinfo (~> 1.2)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"handlebars": "^4.7.7",
5454
"search-insights": "^2.0.3",
5555
"tap-spot": "^1.1.1",
56-
"tippy.js": "^6.3.1",
56+
"tippy.js": "5.2.0",
5757
"typewriter": "^7.4.1",
5858
"webpack-dotenv-plugin": "^2.1.0"
5959
}

src/_includes/content/functions/runtime.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,24 @@ Only the [`crypto` Node.js module](https://nodejs.org/dist/latest-v10.x/docs/api
3131

3232
##### Caching
3333

34-
Per-function global caching is available in the `cache` namespace. The following functions are available:
34+
Basic cache storage is available through the `cache` object, which has the following methods defined:
3535

3636
- `cache.load(key: string, ttl: number, fn: async () => any): Promise<any>`
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. 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.
3838
- `cache.delete(key: string): void`
39-
- Forcefully remove the value associated with the `key`.
39+
- Immediately remove the value associated with the `key`.
4040

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.
4147
The following example gets a JSON value through the cache, only invoking the callback as needed:
4248

4349
```js
4450
const ttl = 5 * 60 * 1000 // 5 minutes
45-
const val = await cache.load("mycachekey", ttl, () => {
51+
const val = await cache.load("mycachekey", ttl, async () => {
4652
const res = await fetch("http://echo.jsontest.com/key/value/one/two")
4753
const data = await res.json()
4854
return data

src/connections/destinations/catalog/actions-amplitude/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ When you send an "Order Completed" event from Segment, an "Order Completed" even
170170

171171
#### Track Revenue Per Product
172172

173+
> info ""
174+
> If you use Track Revenue Per Product, add a `revenue` property inside the `products` array of the Order Completed event.
175+
173176
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.
174177

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

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

+130-2
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ Calling the `debug` method turns on debug mode, which logs helpful messages to t
501501

502502
Enable:
503503
```js
504-
analytics.debug();
504+
analytics.debug(true);
505505
```
506506

507507
Disable:
@@ -721,7 +721,135 @@ No, there is no change in behavior to Middlewares.
721721
#### 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?
722722
No, there is no impact to how events filter.
723723

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:
749+
750+
```js
751+
export const lowercase: Plugin = {
752+
name: 'Lowercase events',
753+
type: 'enrichment',
754+
version: '1.0.0',
755+
756+
isLoaded: () => true,
757+
load: () => Promise.resolve(),
758+
759+
track: (ctx) => {
760+
ctx.updateEvent('event', ctx.event.event.toLowerCase())
761+
return ctx
762+
}
763+
}
764+
765+
const identityStitching = () => {
766+
let user
767+
768+
const identity = {
769+
// Identifies your plugin in the Plugins stack.
770+
// Access `window.analytics.queue.plugins` to see the full list of plugins
771+
name: 'Identity Stitching',
772+
// Defines where in the event timeline a plugin should run
773+
type: 'enrichment',
774+
version: '0.1.0',
775+
776+
// use the `load` hook to bootstrap your plugin
777+
// The load hook will receive a context object as its first argument
778+
// followed by a reference to the analytics.js instance from the page
779+
load: async (_ctx, ajs) => {
780+
user = ajs.user()
781+
},
782+
783+
// Used to signal that a plugin has been property loaded
784+
isLoaded: () => user !== undefined,
785+
786+
// Applies the plugin code to every `identify` call in Analytics.js
787+
// You can override any of the existing types in the Segment Spec.
788+
async identify(ctx) {
789+
// Request some extra info to enrich your `identify` events from
790+
// an external API.
791+
const req = await fetch(
792+
`https://jsonplaceholder.typicode.com/users/${ctx.event.userId}`
793+
)
794+
const userReq = await req.json()
795+
796+
// ctx.updateEvent can be used to update deeply nested properties
797+
// in your events. It's a safe way to change events as it'll
798+
// create any missing objects and properties you may require.
799+
ctx.updateEvent('traits.custom', userReq)
800+
user.traits(userReq)
801+
802+
// Every plugin must return a `ctx` object, so that the event
803+
// timeline can continue processing.
804+
return ctx
805+
},
806+
}
807+
808+
return identity
809+
}
810+
811+
// Registers our new plugin into Analytics.js
812+
await window.analytics.register(identityStitching())
813+
```
814+
815+
Here's an example of a `utility` plugin that allows you to change the format of the anonymous_id cookie:
816+
817+
```js
818+
819+
window.analytics.ready(() => {
820+
window.analytics.register({
821+
name: 'Cookie Compatibility',
822+
version: '0.1.0',
823+
type: 'utility',
824+
load: (_ctx, ajs) => {
825+
const user = ajs.user()
826+
const cookieJar = user.cookies
827+
const cookieSetter = cookieJar.set.bind(cookieJar)
828+
829+
// blindly convert any values into JSON strings
830+
cookieJar.set = (key, value, opts) => cookieSetter(key, JSON.stringify(value), opts)
831+
832+
// stringify any existing IDs
833+
user.anonymousId(user.anonymousId())
834+
user.id(user.id())
835+
},
836+
isLoaded: () => true
837+
})
838+
})
839+
```
840+
841+
You can view Segment's [existing plugins](https://github.com/segmentio/analytics-next/tree/master/src/plugins){:target="_blank"} to see more examples.
842+
843+
### Register a plugin
844+
Registering plugins enable you to modify your analytics implementation to best fit your needs. You can register a plugin using this:
845+
846+
```js
847+
// A promise will resolve once the plugins have been successfully loaded into Analytics.js
848+
// You can register multiple plugins at once by using the variable args interface in Analytics.js
849+
await window.analytics.register(pluginA, pluginB, pluginN)
850+
```
851+
852+
## Video Player Plugins
725853

726854
Segment offers video player 'plugins' so you can quickly collect video events using Analytics.js. See the specific documentation below to learn more:
727855

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,41 @@ To upgrade a source to Analytics.js 2.0:
1616
5. Within 5 minutes, the source receives Analytics.js 2.0. No code or tag changes required.
1717
6. Open the Debugger to ensure that events are flowing as expected.
1818

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+
1922
## Automatic migration
2023

2124
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.
2225

2326
| Segment Plan | Upgrade Date |
2427
|--------------| -------------|
2528
| Free | June 15, 2021|
26-
| Team | July 6, 2021 |
29+
| Team | July 6, 2021 |
2730
| Business | TBD |
2831

2932
> info ""
3033
> The plans and dates listed above are subject to change.
3134
3235
## Revert to Analytics.js Classic
3336

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

3639
## Cases that require additional intervention
3740

3841
In some cases, upgrading to Analytics.js 2.0 requires manual effort beyond enabling the Analytics.js 2.0 toggle.
3942

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
4344

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

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
4648

4749
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.
4850

49-
### When using a strict content security policy on the page
51+
### Using a strict content security policy on the page
5052

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:
5254
- `https://cdn.segment.com/v1/projects/<WRITE_KEY>/settings`
53-
- `https://cdn.segment.com/analytics-next/bundles/*`
55+
- `https://cdn.segment.com/analytics-next/bundles/*`
5456
- `https://cdn.segment.com/next-integrations/integrations/*`

src/connections/storage/catalog/amazon-s3/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Segment recommends doing this as a best practice. The following policy strictly
166166

167167
## Region
168168

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+
169172
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).
170173

171174
## Custom Path Prefix

yarn.lock

+10-10
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,6 @@
10791079
resolved "https://registry.yarnpkg.com/@nicolo-ribaudo/chokidar-2/-/chokidar-2-2.1.8-no-fsevents.3.tgz#323d72dd25103d0c4fbdce89dadf574a787b1f9b"
10801080
integrity sha512-s88O1aVtXftvp5bCPB7WnmXc5IwOZZ7YPuwNPt+GtOOXpPvad1LfbmjYv+qII7zP6RU2QGnqve27dnLycEnyEQ==
10811081

1082-
"@popperjs/core@^2.8.3":
1083-
version "2.10.1"
1084-
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.10.1.tgz#728ecd95ab207aab8a9a4e421f0422db329232be"
1085-
integrity sha512-HnUhk1Sy9IuKrxEMdIRCxpIqPw6BFsbYSEUO9p/hNw5sMld/+3OLMWQP80F8/db9qsv3qUjs7ZR5bS/R+iinXw==
1086-
10871082
"@segment/loosely-validate-event@^2.0.0":
10881083
version "2.0.0"
10891084
resolved "https://registry.yarnpkg.com/@segment/loosely-validate-event/-/loosely-validate-event-2.0.0.tgz#87dfc979e5b4e7b82c5f1d8b722dfd5d77644681"
@@ -3597,6 +3592,11 @@ pluralize@^8.0.0:
35973592
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1"
35983593
integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==
35993594

3595+
popper.js@^1.16.0:
3596+
version "1.16.1"
3597+
resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.16.1.tgz#2a223cb3dc7b6213d740e40372be40de43e65b1b"
3598+
integrity sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==
3599+
36003600
preact@^10.0.0:
36013601
version "10.5.14"
36023602
resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.14.tgz#0b14a2eefba3c10a57116b90d1a65f5f00cd2701"
@@ -4985,12 +4985,12 @@ tiny-emitter@^2.0.0:
49854985
resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
49864986
integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==
49874987

4988-
tippy.js@^6.3.1:
4989-
version "6.3.1"
4990-
resolved "https://registry.yarnpkg.com/tippy.js/-/tippy.js-6.3.1.tgz#3788a007be7015eee0fd589a66b98fb3f8f10181"
4991-
integrity sha512-JnFncCq+rF1dTURupoJ4yPie5Cof978inW6/4S6kmWV7LL9YOSEVMifED3KdrVPEG+Z/TFH2CDNJcQEfaeuQww==
4988+
tippy.js@5.2.0:
4989+
version "5.2.0"
4990+
resolved "https://registry.yarnpkg.com/tippy.js/-/tippy.js-5.2.0.tgz#5e5a13a196ad2e39c7ee6cac5bfdb0513e797501"
4991+
integrity sha512-bmZu+TP1Fs6+1cq0GI1lfS9R0QxXDthP45zNGSLLMY5p2uC8sODNL4TiUOhEG25q5upk5LUrTnCkc+Q3H2aZJQ==
49924992
dependencies:
4993-
"@popperjs/core" "^2.8.3"
4993+
popper.js "^1.16.0"
49944994

49954995
to-fast-properties@^2.0.0:
49964996
version "2.0.0"

0 commit comments

Comments
 (0)