Skip to content

Commit dcd52be

Browse files
Create faq.md
Create a FAQ section, similar to this other page https://segment.com/docs/protocols/faq/
1 parent 1067b94 commit dcd52be

File tree

1 file changed

+124
-0
lines changed
  • src/connections/sources/catalog/libraries/website/javascript

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: Analytics.js Frequently Asked Questions
3+
strat: ajs
4+
---
5+
6+
## Is there a size limit on requests?
7+
8+
Yes, 32KB per event message. Events with a payload larger than 32KB are accepted by Analytics.js, with the browser returning a `200` response from the Segment servers, but the event will be silently dropped once it enters Segment's pipeline.
9+
10+
## If Analytics.js fails to load, are callbacks not fired?
11+
12+
In the event that Analytics.js does not load, callbacks passed into your API calls do not fire. This is as designed, because the purpose of callbacks are to provide an estimate that the event was delivered and if the library never loads, the events won't be delivered.
13+
14+
## Why do I see a network request to `/m`?
15+
16+
In May 2018, Segment released a change to Analytics.js that collects client-side performance metrics in Analytics.js. This includes metrics like:
17+
18+
- When client side integrations are initialized and when they fail
19+
- When messages are sent to client side integrations and when they fail
20+
21+
Segment added these metrics to proactively identify and resolve issues with individual client-side integrations. These metrics are connected to alerts that notify Segment's on-call engineers to take action on these quickly.
22+
23+
There should be no noticeable impact to your data flow. You may notice Analytics.js make an extra network request in the network tab to carry the metrics data to Segment's servers. This should be very infrequent since the data is sampled and batched every 30 seconds, and should not have any impact of website performance.
24+
25+
## How are properties with `null` and `undefined` values treated?
26+
27+
Segment uses the [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify){:target="blank"} method under the hood. Property values set to `null` or `undefined` are treated in accordance with the expected behaviour for the standard method:
28+
29+
```js
30+
console.log(JSON.stringify({ x: null, y: 6 }));
31+
// expected output: "{"x":null,"y":6}"
32+
33+
console.log(JSON.stringify({ x: undefined, y: 6 }));
34+
// expected output: "{"y":6}"
35+
```
36+
37+
## Can I overwrite the context fields?
38+
39+
Yes. This can be useful if some of these fields contain information you don't want to collect.
40+
41+
For example, imagine that your website allows users to view a receipt for purchases at the URL `https://mywebsite.com/store/purchases`. Your users click a link that redirects to that specific URL, your app sets a `receiptId` in the query string, and returns the appropriate receipt. You also send a Track call to Segment from this page.
42+
43+
Since this `receiptId` might contain sensitive information, you can prevent the context field `page.url` from being included in your Track call by overwriting the field in the `options` parameter, as in the example below:
44+
45+
```js
46+
analytics.track("Receipt Viewed", {}, {
47+
page: {
48+
url: null
49+
}
50+
})
51+
```
52+
This works for any [context field](/docs/connections/spec/common/#context) that Segment automatically collects.
53+
54+
When working with Page calls, you can overwrite context fields by following the same instructions above. However, because the `context.page` fields are also available in the `properties` parameter for page calls, you must also prevent the same fields in the `properties` parameter from being included in your Page call. The example below will allow you to overwrite `url` available in context field `page.url` and properties parameter:
55+
56+
```js
57+
analytics.page("Receipt Page", {
58+
url: null,
59+
},{
60+
page: {
61+
url: null
62+
}
63+
})
64+
```
65+
66+
## Can I add context fields that do not already exist?
67+
68+
Yes. Similar to overwriting context, you can add context fields by passing them into the options object as the third argument of the event call. For example, the analytics.js library does not automatically collect location information. To add this into the context object, pass it into the third argument as in the example below:
69+
70+
```js
71+
analytics.track("Order Completed", {}, {
72+
location: {
73+
latitude: '39.7392',
74+
longitude: '104.9903'
75+
}
76+
})
77+
```
78+
79+
> info ""
80+
> You must pass the context object with the call, event if it's empty, as shown by the empty object in the example above.
81+
82+
Some destinations accept properties only. As a result, custom context fields you add may not forward to these destinations.
83+
84+
## What is the impact of exposing the source's write keys?
85+
86+
For the Segment script to work in the browser, you need to expose the write key in order for client-side tracking to work. Segment's library architecture requires the write key to be exposed, similar to that of other major tools like Google Analytics, Mixpanel, Kissmetrics, Hubspot, and Marketo.
87+
88+
If you see any unusual behavior associated with your write key, you can generate a new key. Navigate to **Connections > Sources** and select your source. On the **Settings** tab, go to the **API Keys** section, and click **Generate New Key**.
89+
90+
If you want to hide the write key, you can use Segment's [HTTP Tracking API source](/docs/connections/sources/catalog/libraries/server/http-api/) or one of the other [server-side libraries](/docs/connections/sources/catalog/#server).
91+
92+
## Will Google Chrome's third-party cookie changes impact Segment Analytics.js?
93+
94+
No, Analytics.js isn't affected by this change. This is because Analytics.js only creates first-party cookies. Unlike third-party cookies, which are set by external services and blocked by the [new Chrome update](https://developers.google.com/privacy-sandbox/3pcd){:target="_blank"}.
95+
96+
Regarding cookies set by [device-mode destinations](/docs/connections/destinations/#connection-modes), it's important to note that Segment's primary function is to load third-party SDKs and forward events to them. As a result, the usage and management of cookies are entirely at the discretion of each individual SDK. For instance, if you have concerns about destinations setting third-party cookies, it's best to consult directly with the destination providers for detailed information. For example, Amplitude, one of the destinations in the Segment catalog, offers [more information on this topic](https://www.docs.developers.amplitude.com/guides/cookies-consent-mgmt-guide/#frequently-asked-questions){:target="_blank"}.
97+
98+
## Does Segment support using strict Content Security Policy (CSP) on the page?
99+
100+
If you're using a security policy that allows JavaScript downloads from specific locations using nonces, then you'll need to update the CSP to include all Segment domains. In addition to allowing the main `analytics.min.js` script, you should also allow the following paths in your CSP:
101+
- `https://cdn.segment.com/v1/projects/<WRITE_KEY>/settings`
102+
- `https://cdn.segment.com/analytics-next/bundles/*`
103+
- `https://cdn.segment.com/next-integrations/integrations/*`
104+
105+
Your CSP may also require allowlisting approved domains, in which case you'll want to allow the following endpoints:
106+
- `api.segment.io`
107+
- `cdn.segment.com`
108+
109+
You'll also need to modify the Segment script with your `nonce` tag, which should match the value specified in your Content Security Policy.
110+
111+
> info ""
112+
> Since Segment interacts with several integrations, support surrounding Content Security Policy issues is limited.
113+
114+
## How is the referrer value set?
115+
116+
The Analytics.js library sets the `context.page.referrer` value from the `window.document.referrer` [property](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer){:target="_blank"} set in the browser. If you notice unexpected referrer values reaching Segment, check how this value is being set on your website.
117+
118+
## Are there any rate limits in place for the CDN settings endpoint?
119+
120+
There are no rate limits in place for the CDN settings endpoint.
121+
122+
123+
124+

0 commit comments

Comments
 (0)