InPost Pay - Analytics - Magento

InPost Pay - Analytics - Magento

 

The complete setup guide for the platforms (GA4, Google Ads, Meta, TikTok, Synerise), including the implementation process, verification, and maintenance, is described in the document: InPost Pay – Marketing Conversions Integration.

Prerequisites

Configuring localStorage via Google Tag Manager

For the InPost Pay analytics system to work correctly, four identifiers must be saved to the browser's localStorage:

  • gclid (Google Ads),

  • fbclid (Meta / Facebook Ads),

  • ttclid (TikTok Ads),

  • client_id (Google Analytics 4 — user identifier).

This data must be available on the frontend, as it is read by the InPost Pay widget at the moment the order is placed.

Step 1: Create a new tag in Google Tag Manager

  1. Go to your GTM container.

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

  3. Select the tag type: Custom HTML.

  4. Paste the following code:

<script> function getQueryParam(paramName) { var query = window.location.search.substring(1); var vars = query ? query.split('&') : []; var i; var pair; var key; var value; for (i = 0; i < vars.length; i++) { pair = vars[i].split('='); key = decodeURIComponent(pair[0] || ''); value = decodeURIComponent(pair[1] || ''); if (key === paramName) { return value; } } return null; } function getCookie(cookieName) { var nameEQ = cookieName + '='; var ca = document.cookie.split(';'); var i; var c; for (i = 0; i < ca.length; i++) { c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); } } return null; } function getGa4SessionId() { try { var cookies = document.cookie.split(';'); var i; var cookie; var parts; var value; for (i = 0; i < cookies.length; i++) { cookie = cookies[i]; while (cookie.charAt(0) === ' ') { cookie = cookie.substring(1, cookie.length); } if (cookie.indexOf('_ga_') === 0) { value = cookie.split('=').slice(1).join('='); if (value) { parts = value.split('.'); if (parts.length >= 3) { return parts[2]; } } } } } catch (e) {} return null; } function saveTrackingIdsToLocalStorage() { try { var gclid = getQueryParam('gclid'); var fbclid = getQueryParam('fbclid'); var ttclid = getQueryParam('ttclid'); var gaClientId = getCookie('_ga'); var gaSessionId = getGa4SessionId(); if (gclid) { localStorage.setItem('gclid', gclid); } if (fbclid) { localStorage.setItem('fbclid', fbclid); } if (ttclid) { localStorage.setItem('ttclid', ttclid); } if (gaClientId) { localStorage.setItem('client_id', gaClientId); } if (gaSessionId) { localStorage.setItem('session_id', gaSessionId); } } catch (e) {} } saveTrackingIdsToLocalStorage(); </script>

Step 2: Set the trigger

  1. Click Triggers and select All Pages.

  2. Save the tag.

Step 3: Test

  1. Open the page with parameters in the URL, e.g., ?gclid=111&fbclid=222&ttclid=333.

  2. In the browser's developer tools (DevTools → Application → localStorage), check that the data has been saved:

localStorage.getItem('gclid') // "111" localStorage.getItem('fbclid') // "222" localStorage.getItem('ttclid') // "333" localStorage.getItem('client_id') // e.g. "GA1.2.1234567890.1234567890"

Final notes

  • If you use Google Consent Mode, make sure this tag fires only after the user has given consent for analytics.

Configuring GA4 in the Magento Module

The InPost Pay module for Magento has built-in integration with GA4 (Measurement Protocol). The instructions below describe the configuration in the Magento admin panel.

Step 1: Retrieve data from Google Analytics 4

  1. Go to the Admin tab in the GA4 panel.

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

  3. Select the data stream you want to send purchase events to.

  4. Copy and save the Measurement ID (format: G-XXXXXXXXXX).

  5. Then select Measurement Protocol API Secrets → Create → copy the Secret value.

Step 2: Configure Magento

Configuration details for the module are provided in the InPost Pay documentation for Magento Widget 2.0.

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

  2. Select the Payment Methods section.

  3. Select InPost Pay > Analytics Settings.

  4. Fill in the following fields:

    • Enable Analytics – select Yes

    • Google Analytics Measurement ID – enter the Measurement ID

    • Google Analytics API Secret – enter the Secret value

  5. Click Save Config.

Optional: Asynchronous data sending via CRON

  • The Enable Asynchronous Analytics Data Sending via CRON field — disabled by default.

  • Once enabled, data will not be sent immediately, but every 5 minutes (default).

  • In the CRON Schedule for Analytics Data Sending field, you can set how often the data is sent.

Note — GA4 event duplication: If you are using the Magento module with built-in GA4 analytics, do NOT enable GA4 in the server-side integration (Cloud Function) at the same time — doing so will result in duplicate purchase events. In that case, only enable Google Ads, Meta, TikTok, and/or Synerise in the Cloud Function.