Skip to content

Commit 86094cd

Browse files
Merge branch 'master' into signals-sampling
2 parents 43056e5 + 3b9a9ee commit 86094cd

40 files changed

+1370
-393
lines changed

packages/browser/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @segment/analytics-next
22

3+
## 1.75.0
4+
5+
### Minor Changes
6+
7+
- [#1160](https://github.com/segmentio/analytics-next/pull/1160) [`bedea03b`](https://github.com/segmentio/analytics-next/commit/bedea03bb50e01a7df71461087a9ec340375906d) Thanks [@MichaelGHSeg](https://github.com/MichaelGHSeg)! - Adding apiHost to the readonly data available from Analytics.settings
8+
39
## 1.74.0
410

511
### Minor Changes

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@segment/analytics-next",
3-
"version": "1.74.0",
3+
"version": "1.75.0",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/segmentio/analytics-next",

packages/browser/src/browser/__tests__/integration.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,12 +1041,15 @@ describe('public settings api', () => {
10411041
cdnSettings: cdnSettingsMinimal,
10421042
})
10431043

1044-
expect(analytics.settings).toEqual({
1045-
writeKey,
1046-
cdnSettings: cdnSettingsMinimal,
1047-
timeout: 300,
1048-
cdnURL: 'https://cdn.segment.com',
1049-
})
1044+
expect(analytics.settings).toEqual(
1045+
expect.objectContaining({
1046+
writeKey,
1047+
cdnSettings: cdnSettingsMinimal,
1048+
timeout: 300,
1049+
cdnURL: 'https://cdn.segment.com',
1050+
apiHost: 'api.segment.io/v1',
1051+
})
1052+
)
10501053
})
10511054

10521055
it('should have a writeKey', async () => {

packages/browser/src/core/analytics/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ import {
5151
} from '../storage'
5252
import { setGlobalAnalytics } from '../../lib/global-analytics-helper'
5353
import { popPageContext } from '../buffer'
54+
import {
55+
isSegmentPlugin,
56+
SegmentIOPluginMetadata,
57+
} from '../../plugins/segmentio'
5458

5559
const deprecationWarning =
5660
'This is being deprecated and will be not be available in future releases of Analytics JS'
@@ -81,13 +85,19 @@ export class AnalyticsInstanceSettings {
8185
*/
8286
readonly cdnSettings: CDNSettings
8387
readonly cdnURL?: string
88+
get apiHost(): string | undefined {
89+
return this._getSegmentPluginMetadata?.()?.apiHost
90+
}
91+
private _getSegmentPluginMetadata?: () => SegmentIOPluginMetadata | undefined
8492

8593
/**
8694
* Auto-track specific timeout setting for legacy purposes.
8795
*/
8896
timeout = 300
8997

90-
constructor(settings: AnalyticsSettings) {
98+
constructor(settings: AnalyticsSettings, queue: EventQueue) {
99+
this._getSegmentPluginMetadata = () =>
100+
queue.plugins.find(isSegmentPlugin)?.metadata
91101
this.writeKey = settings.writeKey
92102
this.cdnSettings = settings.cdnSettings ?? {
93103
integrations: {},
@@ -201,14 +211,15 @@ export class Analytics
201211
super()
202212
const cookieOptions = options?.cookie
203213
const disablePersistance = options?.disableClientPersistence ?? false
204-
this.settings = new AnalyticsInstanceSettings(settings)
214+
205215
this.queue =
206216
queue ??
207217
createDefaultQueue(
208218
`${settings.writeKey}:event-queue`,
209219
options?.retryQueue,
210220
disablePersistance
211221
)
222+
this.settings = new AnalyticsInstanceSettings(settings, this.queue)
212223

213224
const storageSetting = options?.storage
214225
this._universalStorage = this.createStore(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// This file is generated.
2-
export const version = '1.74.0'
2+
export const version = '1.75.0'

packages/browser/src/plugins/segmentio/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ function onAlias(analytics: Analytics, json: JSON): JSON {
5050
return json
5151
}
5252

53+
export type SegmentIOPluginMetadata = {
54+
writeKey: string
55+
apiHost: string
56+
protocol: string
57+
}
58+
export interface SegmentIOPlugin extends Plugin {
59+
metadata: SegmentIOPluginMetadata
60+
}
61+
62+
export const isSegmentPlugin = (plugin: Plugin): plugin is SegmentIOPlugin => {
63+
return plugin.name === 'Segment.io'
64+
}
65+
5366
export function segmentio(
5467
analytics: Analytics,
5568
settings?: SegmentioSettings,
@@ -129,7 +142,12 @@ export function segmentio(
129142
})
130143
}
131144

132-
const segmentio: Plugin = {
145+
const segmentio: SegmentIOPlugin = {
146+
metadata: {
147+
writeKey,
148+
apiHost,
149+
protocol,
150+
},
133151
name: 'Segment.io',
134152
type: 'destination',
135153
version: '0.1.0',

packages/consent/consent-tools/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ withCMP(window.analytics).load('<MY_WRITE_KEY')
9393

9494
## Wrapper Examples
9595

96-
- [OneTrust](../consent-wrapper-onetrust) (beta)
96+
- [OneTrust](../consent-wrapper-onetrust)
97+
- [TrustArc](https://github.com/trustarc/trustarc-segment-wrapper)
9798

9899
## Settings / Options / Configuration
99100

packages/signals/signals-example/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
### Patch Changes
66

7+
- Updated dependencies [[`c8ce6144`](https://github.com/segmentio/analytics-next/commit/c8ce6144b31bddfc66961e979d5648fb66e102e5), [`29d17003`](https://github.com/segmentio/analytics-next/commit/29d1700303d0384fbd01edee9e9ff231f35de9ef), [`bedea03b`](https://github.com/segmentio/analytics-next/commit/bedea03bb50e01a7df71461087a9ec340375906d)]:
8+
- @segment/analytics-signals@1.4.0
9+
- @segment/analytics-next@1.75.0
10+
11+
## null
12+
13+
### Patch Changes
14+
715
- Updated dependencies [[`3f58366b`](https://github.com/segmentio/analytics-next/commit/3f58366b0e01aa723d9d3bbb9fe8549d3082eb8e), [`29e856f9`](https://github.com/segmentio/analytics-next/commit/29e856f9f36088a0dc625014ebda8e09fc3b621e), [`c45d445b`](https://github.com/segmentio/analytics-next/commit/c45d445beb1b1d5b03738557720720d05e9c08a3)]:
816
- @segment/analytics-next@1.74.0
917
- @segment/analytics-signals@1.3.0

packages/signals/signals-example/src/components/ComplexForm.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@ import React, { FormEventHandler, useState } from 'react'
22

33
const ComplexForm = () => {
44
const [inputField, setInputField] = useState('')
5+
const [expectFormError, setExpectFormError] = useState(false)
56
const [selectField, setSelectField] = useState('')
67

8+
const statusCode: number = React.useMemo(() => {
9+
try {
10+
// Change the response status code via the text input field
11+
const val = parseInt(inputField, 10)
12+
return val >= 100 && val <= 511 ? val : 400
13+
} catch (err) {
14+
return 400
15+
}
16+
}, [inputField])
17+
718
const handleSubmit: FormEventHandler<HTMLFormElement> = (event) => {
819
event.preventDefault()
20+
921
const formData = {
22+
status: expectFormError ? statusCode : 200,
1023
inputField,
1124
selectField,
1225
}
@@ -33,16 +46,16 @@ const ComplexForm = () => {
3346
<button data-custom-attr="some-custom-attribute">Example Button</button>
3447
<form onSubmit={handleSubmit}>
3548
<div>
36-
<label htmlFor="ex-input">Input Field:</label>
49+
<label htmlFor="ex-input-text">Input some text:</label>
3750
<input
38-
id="ex-input"
51+
id="ex-input-text"
3952
type="text"
4053
value={inputField}
4154
onChange={(e) => setInputField(e.target.value)}
4255
/>
4356
</div>
4457
<div>
45-
<label htmlFor="ex-select">Select Field:</label>
58+
<label htmlFor="ex-select">Select an option:</label>
4659
<select
4760
id="ex-select"
4861
value={selectField}
@@ -55,7 +68,16 @@ const ComplexForm = () => {
5568
<option value="Option 2">Option 2</option>
5669
</select>
5770
</div>
58-
<button type="submit">Submit</button>
71+
<div>
72+
<label htmlFor="ex-checkbox">{`Force submit network status: ${statusCode}`}</label>
73+
<input
74+
id="ex-checkbox"
75+
type="checkbox"
76+
checked={expectFormError}
77+
onChange={(e) => setExpectFormError(e.target.checked)}
78+
/>
79+
</div>
80+
<button type="submit">Submit via network req</button>
5981
</form>
6082
<button>
6183
<div>

packages/signals/signals-example/src/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ nav a {
4040
nav a:hover {
4141
color: #007bff;
4242
}
43+
44+
form div {
45+
display: inline-block;
46+
}

0 commit comments

Comments
 (0)