InPost Pay - Analytics - Woocommerce
Prerequisites
Prerequisites - WordPress WooCommerce + Google Tag Manager
In order for the InPost Pay analytics system to work properly, it is necessary to store three tags in the browser's localStorage:
gclid(Google Ads),fbclid(Meta / Facebook Ads),client_id((Google Analytics 4 — user ID).
This data must be available on the frontend side, as it is read by the InPost Pay widget when an order is placed.
Step 1: Create a new tag in Google Tag Manager
Navigate to your GTM container.
Click "Add new tag" and name it, e.g. Save ID to localStorage.
Select tag type: custom HTML.
Paste the following code:
<script>
function saveTrackingIdsToLocalStorage() {
try {
const params = new URLSearchParams(window.location.search);
const gclid = params.get('gclid');
const fbclid = params.get('fbclid');
if (gclid) {
localStorage.setItem('gclid', gclid);
}
if (fbclid) {
localStorage.setItem('fbclid', fbclid);
}
if (typeof gtag === "function") {
gtag('get', 'G-XXXXXXXXXX', 'client_id', function(clientId) {
if (clientId) {
localStorage.setItem('client_id', clientId);
}
});
}
} catch (error) {
console.error('Błąd przy zapisywaniu identyfikatorów do localStorage:', error);
}
}
saveTrackingIdsToLocalStorage();
</script>
Note: Replace G-XXXXXXXXXX with your actual Measurement ID from GA4 (e.g. G-ABC123DEF4).
Step 2: Set the trigger
Click "Triggers" and select All Pages.
Save the tag.
Step 3: Test
Go to the page with the parameters in the URL, e.g. ?gclid=111&fbclid=222.
In the browser's developer tool (DevTools → Application → localStorage), check whether the data has been saved:
localStorage.getItem('gclid') // "111"
localStorage.getItem('fbclid') // "222"
localStorage.getItem('client_id') // np. "GA1.2.1234567890.1234567890"Final notes
The
gtag('get', ...)function only works if GA4 is already loaded correctly on the page.If you are using Google Consent Mode, make sure that this tag is triggered after the user agrees to analytics.
GA4
Configuring GA4 integration with WordPress WooCommerce and InPost Pay
The instructions below provide a step-by-step guide on how to configure a purchase event upload to Google Analytics 4 (GA4) using a backend integration based on Google Cloud Functions.
Step 1: Retrieve the data from Google Analytics 4
Go to the Admin tab on the GA4 panel
Select Admin > Data collection and modification > Data streams
Select the data stream to which you want to upload purchase events
Copy and save Measurement ID from the stream window. You will need it later. Then select Measurement Protocol API Secrets.
Click the Create button
Enter name and click Create
Copy and save Secret value – it will be necessary during function implementation
Step 2: Get your access credentials to the InPost Pay API
In order to connect to the InPost Pay API and export purchase data, you will need two values:
client_idclient_secret
Information on how to obtain these values can be found in the Authorization and Technical Requirements | Merchant account configuration production environment.
Step 3: Implement the integration in Google Cloud
Requirements:
Google Cloud (GCP) account with billing enabled
gcloud (Google Cloud SDK) tool installed
Basic terminal (cmd / bash) knowledge
Python 3.11 (locally)
Folder with 3 files
main.pyrequirements.txtdeploy.sh
You can download and unzip the file manually via a browser.
Launch the terminal and navigate to the folder containing the files
Example:cd ~/Pobrane/cloud-function-ga4Grant permissions to run the deployment script
chmod +x deploy.shRun the deployment script
./deploy.shScript will ask you to enter input data:
Your project ID in Google Cloud (e.g. my-eu-project-123)
Region (you can press Enter – by default: europe-central2)
client_idandclient_secretfrom InPost PayMeasurement IDandAPI Secretfrom GA4
The script will:
set a GCP project
create secrets using the provided data
assign appropriate privileges to functions
implement the HTTP function (Cloud Function Gen2)
set a schedule to automatically call the function every 30 minutes
Check function
Once deployment is completed, the following message will be displayed in the terminal:
Function has been deployed and run schedule has been set.
You can also go to Google Cloud Console → Cloud Run functions → check inpost-ga4-integration function status.
What next?
Now, every 30 minutes, the function will independently:
connect to the InPost Pay API
collect purchase data
send them as purchase events to GA4
If you want, you can manually run the function via GCP to test how it functions.
How to download deployment files?
You can download the files from InPost Pay documentation.
Click below and download
cloud-function-ga4.zip
Send the file to the server, to the cloud or unzip it locally.
Google Ads
Configuring the import of conversions from GA4 to Google Ads (Woocommerce)
To track conversions originating from GA4 integration and use them in Google Ads (e.g. to optimize campaigns), you need to link accounts and import purchase events as conversions.
You will find a step-by-step instruction on how to do that below.
Step 1: Connect Google Analytics 4 with Google Ads
Log in to the Google Analytics 4 account.
Go to the Administrator (Admin) tab.
In the Property column, click Google Ads Links.
Click + to add a new link.
Select the Google Ads account you want to link.
Confirm and finish configuration.
The linked Google Ads account will be able to collect data on conversions from GA4.
Step 2: Configure the import of conversions in Google Ads
Log in to the linked Google Ads account.
Go to Tools and Settings > Measurement > Conversions.
Click New conversion > Import.
Select Google Analytics 4: events.
Select the linked GA4 service.
Select events to be imported, e.g. purchase.
Click Import and continue.
Once the events are imported, they will be visible in the Google Ads panel as a source of GA4 conversions.
Step 3: Make sure the conversions are being reported
Go to the Google Ads > Conversions panel.
Check whether the selected events have the "Receiving Data" status.
Data should start to appear after several hours, if the GA4 integration is functioning correctly.
Comments
GA4 no longer supports session-based conversion – a conversion is assigned to the user based on the attribution model selected in Google Ads. Purchaseevents must contain transaction_id – this ensures correct deduplication.
Sources and Google documentation: