stape / gtm-server-side-magento-module

stape/gtm-server-side-magento-module

Stape Conversion Tracking Magento Module

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: N/A Security: Pass GPL-3.0-only

Are you the maintainer of stape?

Packagento pulls stape's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

Stape GTM Server Side Magento Module

If you have your store on Magento, Stape's GTM Server Side extension for Magento 2 can simplify the process and open up the world of server-side tagging.

The list of e-commerce events:

  • Collection view
  • View Item
  • Add to cart
  • Begin checkout
  • Add payment info
  • Purchase

User data:

  • Email
  • First name
  • Last name
  • Customer ID

Same-origin proxy (Beta)

Serve the GTM loader and all sGTM traffic from your own store domain: requests to a
first-party path (e.g. /gtm/) are transparently forwarded by Magento to your Stape
sGTM container — no DNS, CDN or reverse-proxy setup required.

Enable it under Stores → Configuration → Stape → Stape Conversion Tracking → General →
Same-origin proxy (Beta)
and set:

  • Proxy path — must start with / (e.g. /gtm). Any query string or fragment is dropped, duplicate slashes are collapsed and a trailing slash is removed, so /gtm/ is stored as /gtm.

  • Container API key — the full Stape container API key (not the container identifier).

After saving, use the Test connection button to verify the path is not shadowed by an
existing route, URL rewrite, redirect, or CDN/web-server rule.

Notes:

  • If your nginx/Apache serves .js (or other static extensions) directly, requests under
    the proxy path with those extensions bypass PHP. The module works around this with the
    .load extension, but you can also route the proxy path to Magento explicitly, e.g. nginx:

    location ^~ /gtm/ { try_files $uri /index.php$is_args$args; }
    
  • Proxy responses keep the cache lifetime your Stape container sets, but are always marked private, so browsers may reuse them while Magento's full page cache and any standards-compliant shared cache pass them through. Add an explicit rule if a cache in front of Magento is configured to ignore origin cache headers, e.g. Varnish VCL:

    sub vcl_recv {
        if (req.url ~ "^/gtm/") {
            return (pass);
        }
    }
    

    On a CDN, create an equivalent bypass rule for the same path prefix. Replace /gtm/ with the configured proxy path in both cases.

  • While the same-origin proxy is fully configured, Cookie Keeper is superseded by
    first-party delivery and treated as disabled.

  • The container registers its service worker from a proxied document using a relative
    URL, which the module rewrites to the .load extension so it resolves through the proxy
    like the loader does. No extra configuration is needed if you already route the proxy
    path to Magento explicitly (see the nginx snippet above).

  • If CSP restrict mode is enabled (Stores → Configuration → Security → Content Security
    Policy
    ), it is not applied to same-origin proxy responses, since proxied documents come
    from the container, not Magento, and the storefront policy could only break them.

Useful links:

Changelog

v1.0.46

  • fixed storefront crash when the domain list URL is empty, the cookie domain now falls back to the store host;
  • fixed the cookie plugin running when the module or Cookie Keeper is disabled;

v1.0.45

  • added same-origin proxy (Beta): serve the GTM loader and all sGTM traffic from the store's own domain via a configurable first-party path, with container API key parsing, custom-loader integration, admin Test connection button and save-time path conflict detection;

v1.0.44

  • replaced base prices with display prices;
  • fixed currency discrepancies;
  • fixed item price without tax;
  • added "Exclude Tax from Item price" option, item prices and line totals include tax by default;
  • fixed quote item prices being pushed in base currency instead of quote currency;
  • fixed add_to_cart and remove_from_cart value not accounting for quantity and not matching item price;
  • added missing currency to the remove_from_cart event;
  • added "Use Display Currency for Amounts" option, amounts and currency codes use the base currency by default;
  • fixed catalog prices being pushed in base currency while labelled with the display currency code;
  • fixed add_payment_info item prices being pushed in base currency while labelled with the quote currency code;
  • grouped the transition options into a dedicated "Transition Settings" section in admin;

v1.0.43

  • fixed CSP compatibility for config-stored GTM snippet by whitelisting its inline scripts via content hash (full page cache safe);
  • fixed price formatting to be locale agnostic;

v1.0.42

  • added EU API endpoint as backup for custom loader generation;
  • fixed HTTP status code handling from webhook responses;
  • fixed HYVA cart events registry issue;

v1.0.41

  • added try/catch block for product collection;

v1.0.40

  • fixed issue with refund webhook;

v1.0.39

  • fixed exception thrown during config save with empty custom loader;

v1.0.38

  • fixed HEREDOC error happening with html minify enabled in production mode;

v1.0.37

  • added logic to generate GTM snippet via API;

v1.0.36

  • added admin configuration option to control purchase webhook;
  • added payment_type param for purchase webhook;
  • added shipping_tier param for purchase webhook;

v1.0.35

  • fixed PHP7.4 backward compatibility;
  • fixed CSP issue on checkout;

v1.0.34

  • improved SKU tracking

v1.0.33

  • added cart state to datalayer events;
  • extended cookies list;

v1.0.32

  • datalayer event value param added;

v1.0.31

  • renamed module in admin panel;
  • added select_item event;
  • added item_variant param to datalayer;

v1.0.30

  • added module version header;

v1.0.29

  • img-src CSP rule added;

v1.0.28

  • added PHP 8.4 compatibility;
  • fixed code style;

v1.0.27

  • added option to enable/disable '_stape' suffix in Datalayer events;

v1.0.26

  • removed unneeded CSP rules
  • added option to configure collection size for datalayer

v1.0.24

  • added caching of cookie domain when generating _sbp cookie
  • Fixed issue with the overridden price formatter pattern
  • Fixed billing address overwritten by shipping address issue

v1.0.23

  • added logic to fetch add to cart info and send the event if only productIds array is available

v1.0.22

  • fixed duplicate address creation for logged in customer on checkout

v1.0.21

  • removed Stape analytics option as no longer needed

v1.0.20

  • removed usage of md5 hash

v1.0.19

  • Implemented custom GTM loader generation logic with prefix as well as container id

v1.0.18

  • Fixed potential issue with sending multiple purchase webhook events.

v1.0.17

  • Hyva theme compatibility added.

v1.0.16

  • acl.xml added.

v1.0.15

  • fixed logic to trim GTM- only when custom loader and custom domain are populated.

v1.0.14

  • fixed xml layouts.
  • changed class methods visibility from private to public.

v1.0.13

  • fixed broken url generation logic.

v1.0.12

  • added quote_id param to purchase event and webhook.

v1.0.11

  • Update snippets with new param names and format.

v1.0.10

  • Fixed item price for purchase_stape event to include tax.

v1.0.9

  • Fixed issue with cookie being re-generated on every page load.

v1.0.2

  • Fixed issue with main snippet not showing when cookie keeper enabled.

v1.0.1

  • Set _sbp cookie logic added, unneeded functionality cleaned.

v1.0.0

  • Main functionality implemented.
Versions
Version Stability QA Status Compatibility Released
1.0.46 stable Fail Magento 2.4.7-2.4.9 Details 2026-10-20 16:26:33
1.0.45 stable Fail Magento 2.4.7-2.4.9 Details 2026-10-14 13:53:53
1.0.44 stable Fail Magento 2.4.7-2.4.9 Details 2026-08-18 07:48:52
1.0.43 stable Fail Magento 2.4.7-2.4.9 Details 2026-07-14 08:11:13
1.0.42 stable Fail Magento 2.4.7-2.4.9 Details 2026-06-24 10:46:49
1.0.41 stable Fail Not yet tested Details 2026-04-29 11:24:37
1.0.40 stable Not tested Not yet tested Details 2026-04-20 09:37:56
1.0.39 stable Not tested Not yet tested Details 2026-04-16 07:25:56
1.0.38 stable Not tested Not yet tested Details 2026-04-02 13:26:05
1.0.37 stable Not tested Not yet tested Details 2026-02-09 13:41:00
1.0.36 stable Not tested Not yet tested Details 2026-01-23 08:25:07
1.0.35 stable Not tested Not yet tested Details 2026-01-15 12:52:18
1.0.34 stable Not tested Not yet tested Details 2025-12-29 14:24:02
1.0.33 stable Not tested Not yet tested Details 2025-12-11 08:58:02
1.0.32 stable Not tested Not yet tested Details 2025-11-10 12:25:45
1.0.31 stable Not tested Not yet tested Details 2025-10-20 12:33:43
1.0.30 stable Not tested Not yet tested Details 2025-09-10 11:08:10
1.0.29 stable Not tested Not yet tested Details 2025-08-27 08:07:47
1.0.28 stable Not tested Not yet tested Details 2025-07-28 09:16:18
1.0.27 stable Not tested Not yet tested Details 2025-07-22 20:06:00
1.0.26 stable Not tested Not yet tested Details 2025-07-09 08:38:25
1.0.25 stable Not tested Not yet tested Details 2025-03-21 14:53:34
1.0.24 stable Not tested Not yet tested Details 2025-02-24 11:15:48
1.0.23 stable Not tested Not yet tested Details 2025-01-21 13:34:17
1.0.22 stable Not tested Not yet tested Details 2024-12-19 11:13:07
1.0.21 stable Not tested Not yet tested Details 2024-12-18 11:47:46
1.0.20 stable Not tested Not yet tested Details 2024-10-24 12:51:54
1.0.19 stable Not tested Not yet tested Details 2024-10-24 10:53:03
1.0.18 stable Not tested Not yet tested Details 2024-09-08 19:55:06
1.0.17 stable Not tested Not yet tested Details 2024-08-16 19:00:17
1.0.16 stable Not tested Not yet tested Details 2024-06-20 06:13:22
1.0.15 stable Not tested Not yet tested Details 2024-04-30 07:18:20
1.0.14 stable Not tested Not yet tested Details 2024-04-23 19:19:27
1.0.13 stable Not tested Not yet tested Details 2024-04-04 20:01:01
1.0.12 stable Not tested Not yet tested Details 2024-03-25 20:36:35
1.0.11 stable Not tested Not yet tested Details 2024-03-06 21:34:33
1.0.10 stable Not tested Not yet tested Details 2024-01-18 08:53:06
1.0.9 stable Not tested Not yet tested Details 2023-12-22 21:49:36
1.0.8 stable Not tested Not yet tested Details 2023-10-03 09:35:51
1.0.7 stable Not tested Not yet tested Details 2023-09-21 09:12:17
1.0.6 stable Not tested Not yet tested Details 2023-09-14 13:44:14
1.0.5 stable Not tested Not yet tested Details 2023-08-04 19:55:58
1.0.4 stable Not tested Not yet tested Details 2023-05-15 20:11:30
1.0.3 stable Not tested Not yet tested Details 2023-05-15 19:31:24
1.0.0-dev dev Not tested Not yet tested Details 2023-05-10 11:40:07

Requires 6

Package Constraint
guzzlehttp/guzzle ^6.3.3 || ^7.0
guzzlehttp/psr7 ^1.6 || ^2.0
jeremykendall/php-domain-parser ^6.0
php >=7.4.0
psr/http-factory ^1.0
psr/http-message ^1.0 || ^2.0

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Warning 2 2 warnings (ruleset: Magento2)
PHPMD Warning 39 39 rule violations (IfStatementAssignment:24, UnusedFormalParameter:8, MissingImport:2, ExcessiveClassComplexity:1, ExcessiveParameterList:1)
Cpd Warning 1 1 duplicated chunk spanning 47 total lines (min-lines=5, min-tokens=70)
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 7 7
2.4.9 7 7

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
GPL-3.0-only
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.