Skip to content

Commit 0a94149

Browse files
Merge pull request #6802 from segmentio/prigiattiperrut-patch-4
Create faq.md
2 parents 486d66e + b7bb820 commit 0a94149

File tree

2 files changed

+127
-0
lines changed
  • src
    • _data/sidenav
    • connections/sources/catalog/libraries/website/javascript

2 files changed

+127
-0
lines changed

src/_data/sidenav/strat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ sections:
122122
title: Querystring API
123123
- path: /connections/sources/catalog/libraries/website/javascript/troubleshooting
124124
title: Troubleshooting
125+
- path: /connections/sources/catalog/libraries/website/javascript/faq
126+
title: Analytics.js FAQ
125127

126128

127129
- slug: ios
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
title: Analytics.js Frequently Asked Questions
3+
strat: ajs
4+
---
5+
6+
## Is there a size limit on requests?
7+
8+
Yes, the limit is 32KB per event message. Events with a payload larger than 32KB are accepted by Analytics.js and Segment servers return a `200` response , but the event is 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 began collecting 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 extra network request is not made frequently, since the data is sampled and batched every 30 seconds.
24+
25+
## How are properties with `null` and `undefined` values treated?
26+
27+
Segment treats property values set to `null` as null values and drops events set to`undefined`.
28+
29+
For example:
30+
31+
```js
32+
console.log(JSON.stringify({ x: null, y: 6 }));
33+
// expected output: "{"x":null,"y":6}"
34+
35+
console.log(JSON.stringify({ x: undefined, y: 6 }));
36+
// expected output: "{"y":6}"
37+
```
38+
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.
39+
## Can I overwrite the context fields?
40+
41+
Yes. This can be useful if some of these fields contain information you don't want to collect.
42+
43+
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.
44+
45+
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 following example:
46+
47+
```js
48+
analytics.track("Receipt Viewed", {}, {
49+
page: {
50+
url: null
51+
}
52+
})
53+
```
54+
This works for any [context field](/docs/connections/spec/common/#context) that Segment automatically collects.
55+
56+
When working with Page calls, you can overwrite context fields by following the above instructions. 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. Use the code in the following example to overwrite `url` available in context field `page.url` and properties parameter:
57+
58+
```js
59+
analytics.page("Receipt Page", {
60+
url: null,
61+
},{
62+
page: {
63+
url: null
64+
}
65+
})
66+
```
67+
68+
## Can I add context fields that do not already exist?
69+
70+
Yes. 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, but you can add it to the context object. To add location information into the context object, pass it into the third argument as in the following example:
71+
72+
```js
73+
analytics.track("Order Completed", {}, {
74+
location: {
75+
latitude: '39.7392',
76+
longitude: '104.9903'
77+
}
78+
})
79+
```
80+
81+
> info ""
82+
> You must pass the context object with the call, even if it's empty.
83+
84+
Some destinations accept properties only. As a result, custom context fields you add may not forward to these destinations.
85+
86+
## What is the impact of exposing the source's write keys?
87+
88+
Segment's library architecture requires you to expose the write key for client-side tracking to work. Other major tools, like Google Analytics, Mixpanel, Kissmetrics, Hubspot, and Marketo, also require you to expose your write key.
89+
90+
If you see any unusual behavior associated with your write key, generate a new key immediately. To 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**.
91+
92+
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).
93+
94+
## Will Google Chrome's third-party cookie changes impact Segment Analytics.js?
95+
96+
No, Analytics.js isn't affected by this change. Google's [third-party cookie deprecation](https://developers.google.com/privacy-sandbox/3pcd){:target="_blank"} only blocks third-party cookies, or cookies set by external services. Analytics.js creates first-party cookies, which are cookies created and stored by the website an end-user is browsing.
97+
98+
99+
## Does Segment support using strict Content Security Policy (CSP) on the page?
100+
101+
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:
102+
- `https://cdn.segment.com/v1/projects/<WRITE_KEY>/settings`
103+
- `https://cdn.segment.com/analytics-next/bundles/*`
104+
- `https://cdn.segment.com/next-integrations/integrations/*`
105+
106+
Your CSP may also require allowlisting approved domains, in which case you'll want to allow the following endpoints:
107+
- `api.segment.io`
108+
- `cdn.segment.com`
109+
110+
You'll also need to modify the Segment script with your `nonce` tag, which should match the value specified in your Content Security Policy.
111+
112+
> info ""
113+
> Since Segment interacts with several integrations, support surrounding Content Security Policy issues is limited.
114+
115+
## How is the referrer value set?
116+
117+
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.
118+
119+
## Are there any rate limits in place for the CDN settings endpoint?
120+
121+
There are no rate limits in place for the CDN settings endpoint.
122+
123+
124+
125+

0 commit comments

Comments
 (0)