Collection methods
Once you have chosen to implement Piano Analytics via our SDKs, our collection API or a TMS, thanks to our dedicated article, you can choose the collection method that suits you best.
Piano collection endpoint
The Piano collection endpoint is the "standard" collection you usually start with.
It is simple and works without any configuration on your side.

To find your collection domain, you can go directly to our Collection Domains tool:

You can pick any of the collection domains, they are dedicated to your organization and only your sites can collect data on them.
Please note that the example here is based on a SDK implementation. The same applies to a Collection API implementation. Check the dedicated article to understand the difference.
Custom Domain Data Collection
To guarantee data collection in the best conditions, we provide the ability to send events to our servers with a CNAME from one of your subdomains.
By using a custom domain, you keep your events, and collect more while keeping our SLAs.

Please note that the example here is based on a SDK implementation. The same applies to a Collection API implementation. Check the dedicated article to understand the difference.
If you want more information related to our Custom Domain Data Collection method, don't hesitate to consult the dedicated article in our Help Center.
If you want to reach the CDDC configuration interface, please follow this link.
You can find the documentation for renewing process here.
Proxify your collection
To maximize data collection, set up a proxy between your visitors and Piano collection servers. This is usually done on your CDN. Any proxy that can apply the rules below works the same way.

Before you begin
- Your site is already served by a CDN or a load balancer that can route by path and set the
Hostheader. - Every organization has a dedicated collection domain on
pa-cd.com. For this proxy, the origin must be that collection domain. A Custom Domain (CDDC) cannot be the origin. - You have chosen a path on your site that is still free. That path is not the site root
/.
Choose the collection path
We recommend reserving one path on your site for Piano collection. Visitors call that path. The CDN forwards the request to your pa-cd.com collection domain and keeps the query string.
The collection API accepts one path segment on that domain. /event is the recommended one, and it is the SDK default when you collect without a proxy. Another segment, such as /piano, works too.
The collection API rejects:
/: the root of the collection domain/collect/analytics: a path with more than one segment
The provider steps below forward /piano unchanged. Rewriting that path is also valid, as long as the origin receives one segment. /event is the recommended target when you rewrite.
- The browser sends
https://www.example.com/piano?<query> - The origin receives
https://<xxxxxxx>.pa-cd.com/piano?<query>
A path with more than one segment has to be rewritten. /collect/analytics on the site becomes one segment on the origin:
- The browser sends
https://www.example.com/collect/analytics?<query> - The origin receives
https://<xxxxxxx>.pa-cd.com/event?<query>
Routing rules
Apply these rules to the collection path. Give that route a higher priority than the default route of the site, so the site origin does not receive collection hits.
- Forward the full visitor request, then drop headers you must not send on (sensitive cookies, for example).
- When a full forward is not possible, the origin request still includes:
Host: the collection domain (<xxxxxxx>.pa-cd.com), so the TLS certificate presented by the origin matches that name. Do not send the visitor hostname.X-Forwarded-For: the visitor IP address.User-Agent, Client Hints (Sec-Ch-Ua*),Accept-Language, andReferer.- The cookies used for collection:
atid,atidx, andidrxvr. These names can change.
- Keep the full query string. The path on the origin must be one segment. Forwarding the visitor path unchanged is valid when it already is one segment. Rewriting it to another single segment, preferably
/event, is also valid. A path with several segments, such as/collect/analytics, has to be rewritten. - Keep the HTTP method of the visitor request (
GETorPOST), including the request body onPOST. - Disable caching. Every request received on this path is forwarded to the collection domain.
- Use the collection hostname as the origin. Do not pin a single IP address.
- Follow the DNS TTL of the origin (60 seconds). Origin IP addresses change over time and by location.
- The origin publishes several IP addresses for one location. Spread requests across all of them. At 1000 requests/s, a DNS answer with 4 addresses means about 250 requests/s on each address.
Route traffic
- Cloudflare
- Amazon CloudFront
- Akamai
- Fastly
- Google Cloud
- Other
Create two rules that match the visitor path. The hostname visitors use (www.example.com) must be proxied through Cloudflare. This example forwards /piano unchanged. To rewrite a multi-segment path, add a URL Rewrite Rule that sets the path to /event. Match the other rules on the visitor path, because a rewrite runs first.
Cloudflare can only override the DNS record to a hostname that already exists in this zone. Create that record before the origin rule. Visitors never call it. The browser still sends hits to https://www.example.com/piano.
- In DNS, add a record dedicated to collection, for example
piano-collect.example.com.- Type:
CNAME - Target:
<xxxxxxx>.pa-cd.com
- Type:
- Open Rules > Overview > Create rule > Origin Rule.
- Custom filter expression:
(http.request.uri.path eq "/piano")- A Cloudflare rule applies to the whole zone. As a best practice, match the site hostname as well:
(http.host eq "www.example.com" and http.request.uri.path eq "/piano")
- A Cloudflare rule applies to the whole zone. As a best practice, match the site hostname as well:
- Host Header > Rewrite to:
<xxxxxxx>.pa-cd.com - SNI: Preserve
- DNS Record > Override to:
piano-collect.example.com
- Custom filter expression:
- Open Caching > Cache Rules > Create rule, with the same expression.
- Cache eligibility: Bypass cache.
- Leave
X-Forwarded-Foras Cloudflare sets it. The visitor IP must stay in that header.
Add an origin and a behavior on a distribution that already serves your site. No extra DNS record is required. This example forwards /piano unchanged. To rewrite a multi-segment path, associate a viewer-request function that sets request.uri to /event and leaves request.querystring as it is.
- On your distribution, create an origin.
- Origin domain:
<xxxxxxx>.pa-cd.com - Protocol: HTTPS only
- HTTPS port:
443 - Minimum origin SSL protocol: TLSv1.2
- Origin path: leave empty
- Name: any name you like
- Origin domain:
- Create a behavior and move it above the default behavior.
- Path pattern:
/piano - Origin: the origin from step 1
- Compress objects automatically: No
- Viewer protocol policy: HTTPS only
- Allowed HTTP methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE (
POSTis only available in this set) - Cache policy:
CachingDisabled - Origin request policy:
AllViewerExceptHostHeader
- Path pattern:
Add a rule on a new property version. In Property Manager, the bottom-most matching rule wins for behaviors that exclude each other, so place this rule below the default origin rule. Activate it on staging before production.
- Add a rule named
Piano collection. - Add a match: Path > is one of >
/piano. - Add the Origin Server behavior.
- Origin Server Hostname:
<xxxxxxx>.pa-cd.com - Forward Host Header: Origin Hostname
- Origin TLS Certificate Verification: Platform Settings, so the certificate is checked against that hostname
- Origin Server Hostname:
- Add Caching and select Bypass cache. The path
/pianois forwarded unchanged. To rewrite a multi-segment path, add Modify Outgoing Request Path, action Replace the entire path, replace with/event, and keep the query parameters. - Forward the visitor IP in
X-Forwarded-For. Add Modify Outgoing Request Header:- Action: Modify when the header is already sent, otherwise Add
- Custom Header Name:
X-Forwarded-For - Header Value or New Header Value:
{{builtin.AK_CLIENT_REAL_IP}}
- Keep
User-Agent,Accept-Language,Referer,Sec-Ch-Ua*, and cookies on the outgoing request. AllowGETandPOST.
The new host receives only the collection path, and forwards /piano unchanged. return(pass) skips the cache. To rewrite a multi-segment path, set bereq.url to /event plus the query string in vcl_pass (a pass does not run vcl_miss; add the same snippet there too if the request is not passed).
- Create a Request condition named
Piano collection path.- Apply if:
req.url.path == "/piano"
- Apply if:
- Create a host named
Piano collection.- Address:
<xxxxxxx>.pa-cd.com - Attach the condition from step 1
- Override host:
<xxxxxxx>.pa-cd.com
- Address:
- Add a VCL snippet, Within subroutine
vcl_recv, namedPiano collection pass:
if (req.url.path == "/piano") {
return (pass);
}
- Keep Fastly's
X-Forwarded-Forheader so it still carries the visitor IP. Activate the new version of the service.
Use an existing external Application Load Balancer. The backend is an internet network endpoint group (NEG) aimed at the collection hostname. Match /piano exactly and forward that path. A prefix such as /piano/* would also forward /piano/other, which has more than one segment. To rewrite a multi-segment path, set Path prefix rewrite to /event.
- In Backend configuration, create a backend service named
piano-collection.- Backend type: Internet network endpoint group
- Protocol: HTTPS
- Under Backends, create an internet NEG.
- Network endpoint group type: Internet NEG (Global)
- Add through: Fully qualified domain name and port
- Fully qualified domain name:
<xxxxxxx>.pa-cd.com - Port:
443
- In Advanced configurations, add a custom request header.
- Header name:
Host - Header value:
<xxxxxxx>.pa-cd.com
- Header name:
- Leave Cloud CDN disabled on this backend, then save.
- In Routing rules, add a rule with a higher priority than the default rule.
- Host:
* - Path:
/piano - Backend:
piano-collection
- Host:
routeRules:
- matchRules:
- fullPathMatch: /piano
priority: 1
routeAction:
weightedBackendServices:
- backendService: piano-collection
weight: 100
- The load balancer appends the visitor IP to
X-Forwarded-For. Leave that header in place.
For another CDN, load balancer, or proxy, apply the routing rules with these settings:
- Give the collection route a higher priority than the default route.
- Origin hostname:
<xxxxxxx>.pa-cd.com, over HTTPS. Do not pin one IP address. - Forward
/pianoas/piano. Keep the query string, the HTTP method, and thePOSTbody. Rewrite a multi-segment path to one segment, preferably/event. - Set
Hostto<xxxxxxx>.pa-cd.com. - Send the visitor IP in
X-Forwarded-For. Also forwardUser-Agent,Sec-Ch-Ua*,Accept-Language,Referer, and the cookiesatid,atidx, andidrxvr. - Disable caching for this path.
Point your implementation at this path
The SDK sends hits to collectDomain + path. For a proxied setup, collectDomain is your site and path is the path on your site (piano, without a leading slash). When the CDN rewrites /collect/analytics to /event, path stays collect/analytics: the rewrite happens after the browser.
- JavaScript
- Android (Kotlin)
- iOS (Swift)
pa.setConfigurations({
site: 123456789,
collectDomain: "https://www.example.com",
path: "piano",
});
val configuration = Configuration.Builder(
collectDomain = "https://www.example.com",
site = 123456789,
path = "piano",
).build()
PianoAnalytics.init(applicationContext, configuration)
pa.setConfiguration(ConfigurationBuilder()
.withCollectDomain("https://www.example.com")
.withSite(123456789)
.withPath("piano")
.build()
)
In the browser network panel, the hit goes to the site domain, and the response is not served from cache.
The same two settings exist on the other SDKs. See the JavaScript SDK and the other SDK articles.
A Collection API request uses the same public URL. With the forwarding example above, the collection domain receives that request on /piano:
https://www.example.com/piano?s=<site-id>&idclient=<visitor-id>