Skip to main content

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.

Classic Collection

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

Collection domain

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.

CDDC Collection

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.

CDN Collection

Before you begin​

  • Your site is already served by a CDN or a load balancer that can route by path and set the Host header.
  • 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 /.

The examples below use these values. Edit them to match your setup. Nothing is sent anywhere. Your values stay in this browser.

Collection URL
https:///
The hostname visitors use, and one path segment.
Browserhttps://www.example.com/pianoHost: www.example.com
Collection domainhttps://<xxxxxxx>.pa-cd.com/pianoHost: <xxxxxxx>.pa-cd.com

The CDN forwards the same path and query string, and sets Host to the collection domain.

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.

Rejected paths

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, and Referer.
    • The cookies used for collection: atid, atidx, and idrxvr. 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 (GET or POST), including the request body on POST.
  • 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​

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.

  1. In DNS, add a record dedicated to collection, for example piano-collect.example.com.
    • Type: CNAME
    • Target: <xxxxxxx>.pa-cd.com
  2. 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")
    • Host Header > Rewrite to: <xxxxxxx>.pa-cd.com
    • SNI: Preserve
    • DNS Record > Override to: piano-collect.example.com
  3. Open Caching > Cache Rules > Create rule, with the same expression.
    • Cache eligibility: Bypass cache.
  4. Leave X-Forwarded-For as Cloudflare sets it. The visitor IP must stay in that header.

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.

pa.setConfigurations({
site: 123456789,
collectDomain: "https://www.example.com",
path: "piano",
});

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>