# Piano Analytics

<a href="https://dbdiagram.io/e/684ae2df1dff20a534ca7171/684ae3f71dff20a534ca9d5f" class="button primary" data-icon="table-tree">Prebuilt reports and definition</a>

{% hint style="warning" %}
**Piano Analytics limits the number of rows returned per query to 1,500,000.**\
We split our queries by day and by account, but it's important to understand that if a single query for one account exceeds 1,500,000 rows, the API returns an error.\
As a result, the query fails, and the data is not inserted into our system.

To avoid this, make sure to use the filtering feature to reduce the number of returned rows and stay within the API limits.
{% endhint %}

## Prerequisites

To connect Piano to QUANTI, you need a [Piano](https://piano.io/fr/?utm_source=quanti.io\&utm_medium=partnership\&utlm_campaign=campaign=ecommerce-data-connector) account.

## Setup instructions

### Find your credentials

{% stepper %}
{% step %}
**Access your profile parameters**

Go on your profile parameters to the top-right corner : See profile < API Key<br>

<figure><img src="https://content.gitbook.com/content/oRN0sxIyI0UJdSqkwdBu/blobs/hqdCjY5RZGfUh6wAaMRh/piano1.png" alt="Access path to API keys on Piano interface"><figcaption><p>Access path to API keys on Piano interface<br></p></figcaption></figure>
{% endstep %}

{% step %}
**Create a new API Key**

Create a new API Key clicking on the blue button "Create a new API Key".<br>

<figure><img src="https://content.gitbook.com/content/oRN0sxIyI0UJdSqkwdBu/blobs/jhVHZ5WVoeQxZ1tVW7Zd/piano2.png" alt="Button to generate a new API key on Piano interface" width="263"><figcaption><p>Button to generate a new API key</p></figcaption></figure>
{% endstep %}

{% step %}
**Give it a name and a description**

Give it a name and a description. Let the box ticked and save it.<br>

<figure><img src="https://content.gitbook.com/content/oRN0sxIyI0UJdSqkwdBu/blobs/mW7yOOmtAX5AMA9T1zH0/piano3.png" alt="Description pop-in of API key in Piano interface" width="563"><figcaption><p>Description pop-in of API key</p></figcaption></figure>
{% endstep %}

{% step %}
**Note the API credentials**

Make a note of the API credentials. You will need it to configure QUANTI.
{% endstep %}
{% endstepper %}

### Find your Website ID

Your **Website ID** is in the url when you are connected to your Piano account. This is the value of the parameter **site**.

`https://explorer.atinternet-solutions.com/core/#/overview/overview/020202?period.shortcut=yesterday&period.granularity=3&site=`**`612329`**`&graph.options.defaultlist=minmax&graph.options.comparisonlist=nocomparison&graph.options.eventloglist=eventlog&isIgnoreNullProperties=false`

### Connector configuration

{% stepper %}
{% step %}
**Authorize your account**

1. Access Key and Secret Key retrieved following the steps above.
2. Site ID retrieved following the steps above.
   {% endstep %}

{% step %}
**Connector information**

1. Connector Name : Name your connector. It must be unique.
2. Dataset ID : Define the ID of the dataset. It must not exist yet, as it will be created and data will be sent there.
   {% endstep %}

{% step %}
**Create reports**

Select the pre-built reports you want to activate, and/or create your own custom reports. To help you configure custom reports, refer to the 'Custom reports' chapter below.
{% endstep %}
{% endstepper %}

## Pre-built reports

* **content\_pages**: Contains daily records of user interactions for each website page, enabling content-level performance tracking.
* **traffic\_sources**: Describes how users arrive on the site, with detailed information about traffic origin, campaigns, and referrers.
* **transaction\_source**: Stores transactional data along with marketing attribution fields, providing insight into the source and context of each purchase.

## Custom reports

{% hint style="warning" %}
**Piano Analytics limits the number of rows returned per query to 1,500,000.**\
We split our queries by day and by account, but it's important to understand that if a single query for one account exceeds 1,500,000 rows, the API returns an error.\
As a result, the query fails, and the data is not inserted into our system.

To avoid this, make sure to use the filtering feature to reduce the number of returned rows and stay within the API limits.
{% endhint %}

{% stepper %}
{% step %}
**Retrieve your field names from Piano Analytics**

The easiest way to identify the field names expected by the Piano API is to use the **Data Query** tool directly in the Piano Analytics interface.

* In Piano Analytics, navigate to **Data Query** (top-right corner, icon with 4 squares)

<figure><img src="https://1847929239-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoRN0sxIyI0UJdSqkwdBu%2Fuploads%2F3s2l0X7uoNpNdx8LX0As%2Fimage.png?alt=media&#x26;token=db742f57-4c57-4aa7-993e-985519849838" alt=""><figcaption></figcaption></figure>

* Build the report you want to extract via the QUANTI connector by selecting your dimensions and metrics

<figure><img src="https://1847929239-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoRN0sxIyI0UJdSqkwdBu%2Fuploads%2F8QiRJ96Q1E2tqEfptYzy%2Fimage.png?alt=media&#x26;token=46ce616d-3203-42d5-a592-c6a3f3d9cec4" alt=""><figcaption></figcaption></figure>

* Once your report is configured, click the **copy/paste button** in the top-right corner, then select **Copy the API body (POST)**<br>

<figure><img src="https://1847929239-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoRN0sxIyI0UJdSqkwdBu%2Fuploads%2Fdm7gNJKlUVWwutWW5CE3%2Fimage.png?alt=media&#x26;token=9de1da70-13c1-4276-b6a7-52a4d4b07e99" alt=""><figcaption></figcaption></figure>

* A pop-in appears with the full API body. Retrieve:
  * The content of the `columns` object → this will populate the `fields` array in your JSON
  * The content of the `filter` object (if any) → this will populate the `filter` field in your JSON

<figure><img src="https://1847929239-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoRN0sxIyI0UJdSqkwdBu%2Fuploads%2FiZcVt0TximrPPxpAfrSE%2Fimage.png?alt=media&#x26;token=568ea087-ec8a-4c5b-be99-14d50ad5e430" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Configure the custom report query**

In QUANTI, at the **Create reports** step, click **Add custom report**. A pop-in opens with two steps: **Query** and **Schema**.

In the **Query** step:

* Give your report a name in the **Query name** field — this name will become the table name in your data warehouse

{% hint style="danger" %}
The name chosen for your custom report is the one that names your table in the data warehouse.
{% endhint %}

* Fill in the **Query configuration (JSON)** with the following structure:

```json
{
  "fields": [],
  "sort": [],
  "filter": ""
}
```

* **`fields`** *(required)*: Paste the field names retrieved from Piano Analytics. Each field name must be a quoted string, separated by commas.\
  Example: `"fields": ["src", "page", "m_visits", "m_page_loads"]`
* **`sort`** *(optional)*: List of fields to sort by. Can be left empty.
* **`filter`** *(optional)*: Paste the filter expression copied from the Piano API body. Can be left as an empty string if no filter is needed.

Once your JSON is filled in, click **Next**.
{% endstep %}

{% step %}
**Map your fields (Schema)**

The second step of the pop-in is the **Schema** mapping. QUANTI infers the type of each field and displays them in a table.

For each field, you can:

* Adjust the **Type** (STRING, INTEGER, FLOAT, etc.)
* Check **Unique identifiers** to mark the field as part of the primary key — this should include all dimension fields of your report, as they collectively form the unique identifier of each row
* Check **Metric** to flag a field as a numeric metric

Once all fields are correctly mapped, click **Save** to create the custom report table.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
**Limits**

* Max 50 dimensions and metrics per Custom Report
* Piano Analytics limits the number of rows returned per query to 1,500,000 — use filters to stay within this limit
  {% endhint %}
