Skip to content

Commit ca662c5

Browse files
authored
Merge branch 'master' into doc-351
2 parents e2504e7 + 81375d0 commit ca662c5

File tree

8 files changed

+305
-169
lines changed

8 files changed

+305
-169
lines changed

.github/workflows/unallowed-contributions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222

2323
jobs:
2424
triage:
25-
if: github.repository == 'segmentio/segment-docs' && (github.event.pull_request.user.login != 'markzegarelli' || github.event.pull_request.user.login != 'stayseesong' || github.event.pull_request.user.login != 'pwseg')
25+
if: github.repository == 'segmentio/segment-docs' && github.event.pull_request.user.login != 'markzegarelli' || github.event.pull_request.user.login != 'stayseesong' || github.event.pull_request.user.login != 'pwseg'
2626
runs-on: ubuntu-latest
2727
steps:
2828
- name: Get files changed
@@ -93,4 +93,4 @@ jobs:
9393
console.log("Error creating comment.", err)
9494
}
9595
96-
core.setFailed(workflowFailMessage)
96+
core.setFailed(workflowFailMessage)

src/_data/sidenav/strat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sections:
4646
- path: /connections/destinations/catalog/firebase
4747
title: Google Firebase (mobile analytics) destination
4848
- path: /connections/destinations/catalog/google-analytics
49-
title: Google Analytics destination
49+
title: Google Universal Analytics destination
5050
- path: /connections/destinations/catalog/google-analytics/ga4-plans
5151
title: Google Analytics 4 destination
5252
- path: /connections/destinations/catalog/google-tag-manager

src/config-api/tutorial-javascript-google-analytics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ To set up Segment Protocols through the API you first need to create a personal
3737
3838
1. Log in to your Segment workspace.
3939
2. Click **Settings** in the left navigation bar.
40-
3. Click **Access Management**, then the **Tokens** tab, and click **Create Token**.
40+
3. Go to **Settings > Workspace Settings > Access Management**. Select the **Tokens** tab, and click **Create Token**.
4141
4. For purposes of this demonstration, select **Workspace Owner** as the token's scope.
4242
5. Enter a description for the token. For this demo, we recommend using `demo-token` so it's easy to find and remove later.
4343
6. Click **Create**.

src/connections/destinations/catalog/eloqua/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ the Segment `group` event needs to include the Account's name and groupId. If
6464
you set up a custom Account field called Company in Eloqua, Segment will
6565
automatically map the name of the Account to that field.
6666

67-
Follow the Segment spec to ensure proper mapping of these fields from Segment
68-
`group` traits: https://segment.com/docs/connections/spec/group/#traits.
67+
Follow [Segment's group spec](https://segment.com/docs/connections/spec/group/#traits) to ensure proper mapping of these fields from Segment
68+
`group` traits.
6969

7070
In addition, Segment supports mapping custom `group` traits to Eloqua custom
7171
object fields. To do so, you can set up mappings in the settings for your

src/connections/destinations/catalog/google-analytics/index.md

Lines changed: 108 additions & 108 deletions
Large diffs are not rendered by default.

src/connections/sources/catalog/cloud-apps/salesforce/index.md

Lines changed: 60 additions & 54 deletions
Large diffs are not rendered by default.

src/connections/sources/catalog/libraries/mobile/react-native/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ strat: react-native
44
repo: analytics-react-native
55
---
66

7+
> info "Analytics React Native 2.0 Pilot"
8+
> Analytics React Native 2.0 is available as a public pilot. Use of this pilot is governed by Segment's [First-Access and Beta terms](https://segment.com/legal/first-access-beta-preview/){:target="_blank"}. For more information, see the [Analytics React Native 2.0 GitHub repository](https://github.com/segmentio/analytics-react-native){:target="_blank"}.
79
810
Analytics for React Native makes it easy to send your data to any analytics or marketing tool without having to learn, test or implement a new API every time.
911

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

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)