InPost Pay - Analytics - Magento

InPost Pay - Analytics - Magento

 

Prerequisites

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

  1. Navigate to your GTM container.

  2. Click "Add new tag" and name it, e.g. Save ID to localStorage.

  3. Select tag type: custom HTML.

  4. 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

  1. Click "Triggers" and select All Pages.

  2. Save the tag.

Step 3: Test

  1. Go to the page with the parameters in the URL, e.g. ?gclid=111&fbclid=222.

  2. 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 Magento and InPost Pay

The instructions below provide a step-by-step guide on how to configure a purchase event upload from Magento through the InPost Pay gateway to Google Analytics 4 (GA4) using the Measurement Protocol.

Step 1: Retrieve the data from Google Analytics 4

  1. Go to the Admin tab on the GA4 panel

image-20250529-134025.png

 

  1. Select Admin > Data collection and modification > Data streams

    image-20250529-134210.png
  2. Select the data stream to which you want to upload purchase events

    image-20250529-134326.png
  3. Copy and save Measurement ID from the stream window. You will need it later.
    Then select Measurement Protocol API Secrets.

    image-20250529-134517.png
  4. Click the Create button

    image-20250529-134712.png
  5. Enter name and click Create

    image-20250529-134837.png
  6. Copy and save Secret value – it will be necessary for Magento configuration

    image-20250529-135026.png

Step 2: Configure Magento
Article InPost Pay - Magento (Widget 2.0) | Ustawienia Analityki contains information on the configuration on the InPost Pay module side.

  1. Log in to your Magento admin panel and go to Stores > Configuration

    image-20250529-140404.png
  2. Select the Payment Methods section

    image-20250529-140444.png
  3. Select InPost Pay > Analytics Settings

    image-20250529-140506.png
  4. Fill in the data:
    - Enable Analytics – select Yes
    - Google Analytics Measurement ID – enter the previously saved Measurement ID
    - Google Analytics API Secret – enter the previously saved Secret value
    - Click Save configuration.

    image-20250529-140539.png
  5. Optional: Asynchronous Sending of Analytics Data via CRON
    - Enable Asynchronous Sending of Analytics Data via CRON field – disabled by default.
    - Once enabled, data will not be sent immediately, but rather every 5 minutes (by default).
    - In the CRON Schedule for Sending Analytics Data, you can set the frequency for sending data.

    image-20250529-140558.png

 


Google Ads

Configuring the import of conversions from GA4 to Google Ads (Magento)

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

  1. Log in to the Google Analytics 4 account.

  2. Go to the Administrator (Admin) tab.

  3. In the Property column, click Google Ads Links.

  4. Click + to add a new link.

  5. Select the Google Ads account you want to link.

  6. 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

  1. Log in to the linked Google Ads account.

  2. Go to Tools and Settings > Measurement > Conversions.

  3. Click New conversion > Import.

  4. Select Google Analytics 4: events.

  5. Select the linked GA4 service.

  6. Select events to be imported, e.g. purchase.

  7. 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

  1. Go to the Google Ads > Conversions panel.

  2. Check whether the selected events have the "Receiving Data" status.

  3. Data should start to appear after several hours, if the GA4 integration is functioning correctly.


Notes
GA4 no longer supports session-based conversion – a conversion is assigned to the user based on the attribution model selected in Google Ads. Purchase events must contain transaction_id – this ensures correct deduplication.


Sources and Google documentation: