Google Tag Manager

Set up your GTM account

If you don't have a Google Tag Manager account, you will need to create one. In the Google Analytics dashboard, click on your account tab as shown below.

Then choose the Tag Manager tab. Select your existing related Tag Manager account or create a new one if you don't have any.

Once your GTM account is created, follow the steps outlined in the video below.

  • Create a new container and choose the type as Web.
  • Navigate to the Admin tab for the container.
  • Click Import Container and import the following file.

When the file opens in your browser, right-click and select Save As to download it, then import it into GTM.

  • Choose workspace type New and select Overwrite as the import option, then confirm.
👍

Note:

After importing the container, go to Variables → Measurement ID and replace G-XXXXXXXXXX with your own GA4 Measurement ID.

  • In the left navigation, choose Variables and select Measurement ID. Add your Measurement ID in the variable configuration.
  • Save your ID, then save and publish your container.

Integrate Google Tag Manager

Add the GTM script tags to your site. You can get your container ID from your GTM account.

Head

<!--This is for <head>-->
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-{INSERT ID HERE}');</script>
<!-- End Google Tag Manager -->

Body

<!--This is for <body>-->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-{INSERT ID HERE}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Tracking subscription conversions

Pelcro fires a browser event called PelcroSubscriptionCreate when a subscription is completed. Add the script below to your site to push purchase data into GTM's dataLayer in the correct format. Once this is in place, you can use GTM Data Layer Variables to pass the values to any tag — Google Ads, GA4, Meta Pixel, and others.

<script>
  document.addEventListener('PelcroSubscriptionCreate', function(e) {
    var subs = e.detail && e.detail.data && e.detail.data.subscriptions;
    var latest = subs && subs[subs.length - 1];
    if (!latest) return;

    var zeroDecimalCurrencies = ['jpy','krw','bif','clp','gnf','mga','pyg','rwf','ugx','vnd','xaf','xof','xpf'];
    var currency = (latest.plan.currency || 'usd').toLowerCase();
    var amount = latest.plan.amount || 0;
    var value = zeroDecimalCurrencies.indexOf(currency) >= 0 ? amount : amount / 100;

    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      event: 'purchase',
      transaction_id: latest.id,
      value: value,
      currency: currency,
      affiliation: 'Pelcro',
      coupon: (e.detail.data.coupon && e.detail.data.coupon.code) || null,
      items: [{
        item_id: latest.id,
        item_name: latest.plan.product && latest.plan.product.name,
        item_variant: latest.plan.nickname,
        price: value,
        quantity: 1
      }]
    });
  });
</script>

This script handles zero-decimal currencies (such as JPY and KRW) correctly and reads from the subscription plan — not the invoice — so the value is always accurate.


GTM Data Layer Variables

After the script above fires, the following fields are available in GTM as Data Layer Variables. Go to Variables > New, select Data Layer Variable, and set the key name exactly as shown.

Variable name (GTM)Data layer keyExample value
dlv - valuevalue26
dlv - currencycurrency"usd"
dlv - transaction_idtransaction_id338371
dlv - couponcoupon"PROMO10" or null

Set the Data Layer Version to Version 2 for each variable.


Tracking Google Ads conversions

Create a Custom Event trigger in GTM on the event name purchase (lowercase), then create a Google Ads Conversion Tracking tag with that trigger. Use the variables above to pass value and currency.

<script>
  gtag('event', 'conversion', {
    'send_to': '{AW-CONVERSION_ID/AW-CONVERSION_LABEL}',
    'value': {{dlv - value}},
    'currency': {{dlv - currency}},
    'transaction_id': {{dlv - transaction_id}}
  });
</script>

Setting transaction_id prevents Google Ads from counting the same subscription twice if the tag fires more than once.


Other Pelcro events

Pelcro fires events at every step of the subscription funnel. You can use these to build audience segments, funnel reports, and remarketing lists in GTM.

Event nameWhen it fires
Product Modal ViewedUser opens the product selection modal
Plan Modal ViewedUser opens the plan selection modal
modal subscription create viewedUser reaches the payment step
purchaseSubscription is successfully created
modal subscription success viewedSuccess screen is shown after payment
RegisteredUser creates a new account
Logged inUser signs in

For each event you want to track, create a Custom Event trigger in GTM with the event name exactly as shown above (case-sensitive), then attach whatever tag you need.