Yes, this is possible!
We will use the Offline conversion import option that allows you to import conversions from ad clicks into Google Ads. What you will need is to get a list of Google Click IDs (GCLIDs) associated with the conversion.
The way that this works is when a visitor clicks an ad, Google adds a unique parameter (GCLID) in the URL to the destination. Piwik PRO captures this parameter and stores it in visitor session. You can fetch via API a list of all GCLIDs for the sessions with conversion.
Before we begin, make sure that:
1. Install Insomnia, cURL or other REST API client.
2. Log in to Piwik PRO and create your API credentials (Menu → User panel → API credentials → Generate new credentials)
3. Fetch your access token (see developer’s documentation):
with cURL:
curl -X POST 'https://<your_instance>/auth/token' -H "Content-Type: application/json" --data '{
"grant_type": "client_credentials",
"client_id": "your_API_client_id",
"client_secret": "your_API_client_secret"
}'
with Insomnia:
After you change <your_instance> and <your_API_client_id>, <your_API_client_secret>, click “Refresh token” or make cURL call to check if it’s working correctly.
4. Make the API call
with cURL:
curl --request POST \
--url https://<your_instance>/api/analytics/v1/sessions/ \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/json' \
--data '{
"date_from": "2021-01-01",
"date_to": "2021-03-31",
"website_id": "<your_website_id>",
"offset": 0,
"limit": 10000,
"columns": [
{
"column_id": "campaign_gclid"
}
],
"filters": {
"operator": "and",
"conditions": [
{
"condition": {
"operator": "neq",
"value": ""
},
"column_id": "campaign_gclid"
},
{
"condition": {
"operator": "neq",
"value": 0
},
"column_id": "session_total_goal_conversions"
}
]
},
"format": "csv"
}'
with Insomnia:
- Choose “POST” request type to the following endpoint: https://<your_instance>/api/analytics/v1/sessions/
- Use JSON as a type and paste the following JSON query customizing the <website_id> and dates.
{
"date_from": "2021-01-01",
"date_to": "2021-03-28",
"website_id": "<website_id>",
"offset": 0,
"limit": 100000,
"columns": [
{
"column_id": "campaign_gclid"
}
],
"filters": {
"operator": "and",
"conditions": [
{
"condition": {
"operator": "neq",
"value": ""
},
"column_id": "campaign_gclid"
},
{
"condition": {
"operator": "neq",
"value": 0
},
"column_id": "session_total_goal_conversions"
}
]
},
"format": "csv"
}
- the result of executing the query will be a CSV with timestamps and GCLIDs for all sessions that has at least one conversion
- you can click “Preview” → Save Raw Response to save it to a file
5. Once you have the CSV, open it in Excel or Google Sheets and customize it to the format that is required by Google Ads and follow their import instructions.
PS. We plan to add GCLID as a dimension in Custom Reports editor, so that you can do it directly from Piwik PRO’s user interface.