External Webgains Knowledge Hub
Breadcrumbs

Webgains Container for Publisher Scripts - Integration Guide

Webgains Container for Publisher Scripts - Supported by Neory.

To work with certain technology publishers - especially for retargeting and onsite solutions - you may need to add the publisher scripts to your website. This often involved adding dynamic values from your shop, such as product ids and names, within those scripts.

Webgains makes this easier: Supported by Neory, our solution means advertisers just need to add the Webgains Container tag once, and then will be able to manage all the publisher scripts they choose to work with without any additional code needed.

This guide explains how to set it up the Webgains Container for Publisher Scripts into your website.

Important: You will receive your Container ID from your Webgains Integration Manager. This ID is required for all integrations.

1. General Guidelines

  • Always define window.ntmData before including the General Tag script.

  • Include all required fields for proper integration.

  • Avoid using iFrames, as tracking may fail inside iFrames.

  • Ensure that selected publishers are listed in your CMP if required.

  • Include the General Tag on all pages, after defining window.ntmData.

2. General Tag

The General Tag must be included on all pages. It initializes the container and ensures all tracking data is sent correctly.

<script>
(function(window, document, tagName, dataLayerName, containerId) {
    window[dataLayerName] = window[dataLayerName] || [];
    window[dataLayerName].push({
        'event': 'ntmInit',
        't': new Date().getTime()
    });
    var firstScript = document.getElementsByTagName(tagName)[0];
    var script = document.createElement(tagName);
    var dataParam = dataLayerName !== 'ntmData' ? '&ntmData=' + dataLayerName : '';
    script.async = true;
    script.src = 'http' + (document.location.protocol === 'https:' ? 's' : '') +
                 '://tm.container.webgains.link/tm/a/container/init/' +
                 containerId + '.js?' + dataParam +
                 '&rnd=' + Math.floor(Math.random() * 100000000);
    firstScript.parentNode.insertBefore(script, firstScript);
})(window, document, 'script', 'ntmData', 'YOUR_CONTAINER_ID');
</script>

Notes:

  • Replace YOUR_CONTAINER_ID with your actual Container ID.

  • Must appear after all window.ntmData.push({...}) calls on the page.

3. GDPR / TCF 2.0 Compliance

All tags support TCF 2.0 for GDPR compliance.

Parameter

Required/Recommended

Description

gdpr

Required

-1 = CMP not detected, 0 = GDPR not applicable, 1 = GDPR applies

gdprConsent

Recommended

IAB TCF 2.x consent string (required if gdpr = 1)

pageType

Required

Page type: homepage, generic, category, product, searchresult, wishlist, basket, order

Example GDPR Setup:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "generic"
});
</script>

  • If no CMP is in use, set gdpr = -1 and omit gdprConsent.

4. Page-Specific Tags

All page-specific tags use the same pattern, which can be used as a template for any page type:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",              // GDPR status: -1 = no CMP, 0 = not applicable, 1 = applies
  gdprConsent: "",         // TCF 2.x consent string if applicable
  pageType: "PAGE_TYPE",   // Replace with the type of page: homepage, generic, category, product, searchresult, wishlist, basket, order

  // Page-specific fields (add as needed)
  categoryId: "CATEGORY_ID",   // Required for category/product pages
  categoryName: "CATEGORY_NAME", // Optional for category pages
  productId: "PRODUCT_ID",     // Required for product/order pages
  productPrice: "PRODUCT_PRICE", // Recommended for product/order pages
  productName: "PRODUCT_NAME",  // Recommended for product/order pages
  pageName: "PAGE_NAME",        // Optional for generic pages
  searchTerm: "SEARCH_TERM",    // Required for searchresult pages
  products: [                   // Required for wishlist, basket, order pages
    { id: "PRODUCT_ID", qty: QTY, price: "PRICE", name: "PRODUCT_NAME" }
  ],
  transactionId: "ORDER_ID",   // Required for order pages
  orderValue: "ORDER_VALUE"    // Required for order pages
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

How to Use This Pattern

  1. Set pageType according to the type of page.

  2. Include page-specific fields depending on the page type:

Page Type

Required Fields

Optional Fields

Homepage

pageType, gdpr

gdprConsent

Generic

pageType, gdpr

gdprConsent, pageName

Category

pageType, gdpr, categoryId

gdprConsent, categoryName

Product

pageType, gdpr, categoryId, productId

gdprConsent, productPrice, productName

Search Result

pageType, gdpr, searchTerm, products

gdprConsent

Wishlist

pageType, gdpr, products

gdprConsent

Basket

pageType, gdpr, products

gdprConsent

Order

pageType, gdpr, transactionId, orderValue, products

gdprConsent

  1. Replace placeholders like PAGE_TYPE, CATEGORY_ID, PRODUCT_ID, PRODUCT_NAME, ORDER_ID etc., with your actual site values.

  2. Keep the General Tag script identical for all pages.

4.1 Homepage Tag (Mandatory)

Tracks homepage visits.

Field

Required/Recommended

Notes

gdpr

Required

See GDPR section

gdprConsent

Recommended

Include if GDPR applies

pageType

Required

Must be "homepage"

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "homepage"
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.2 Generic Page Tag (Optional)

Use for pages without a dedicated tag.

Field

Required/Recommended

Notes

pageType

Required

Must be "generic"

pageName

Recommended

Short identifier, e.g., "contact", "faq"

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "",
  pageType:"generic",
  pageName:"contact"
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.3 Category Page Tag (Optional, Recommended)

Tracks user interest in categories.

Field

Required/Recommended

Notes

pageType

Required

Must be "category"

categoryId

Required

Must match catalog ID

categoryName

Recommended

Should match catalog name

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "category",
  categoryId: "cat123",
  categoryName: "Laptops"
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.4 Product Detail Page Tag (Recommended)

Tracks viewed product details.

Field

Required/Recommended

Notes

pageType

Required

Must be "product"

categoryId

Required

Must match catalog

productId

Required

Unique product ID

productPrice

Recommended

Numeric, dot decimal, no thousand separators

productName

Recommended

Short product name

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "product",
  categoryId: "cat123",
  productId: "prod456",
  productPrice: "1299.99",
  productName: "SuperLaptop 15 Pro"
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.5 Search Results Page Tag (Optional, Recommended)

Tracks products from search results.

Field

Required/Recommended

Notes

pageType

Required

Must be "searchresult"

searchTerm

Required

Comma-separated if multiple terms

products

Required

Array of {id:"XXX"} matching catalog

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "searchresult",
  searchTerm: "gaming laptop",
  products: [
    { id: "prod456" },
    { id: "prod789" }
  ]
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.6 Wishlist Page Tag (Optional, Recommended)

Tracks products in user wishlists.

Field

Required/Recommended

Notes

pageType

Required

Must be "wishlist"

products

Required

Array of {id:"XXX"}

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "wishlist",
  products: [
    { id: "prod456" },
    { id: "prod789" }
  ]
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.7 Shopping Basket Tag (Optional, Recommended)

Tracks products in the shopping cart.

Field

Required/Recommended

Notes

pageType

Required

Must be "basket"

products

Required

Array of {id, qty, price, name}. qty integer; price numeric dot decimal

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "basket",
  products: [
    { id: "prod456", qty: 1, price: "1299.99", name: "SuperLaptop 15 Pro" },
    { id: "prod789", qty: 2, price: "499.99", name: "Wireless Mouse" }
  ]
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

4.8 Order Confirmation Page Tag (Mandatory)

Tracks completed orders.

Field

Required/Recommended

Notes

pageType

Required

Must be "order"

transactionId

Required

Unique order number

orderValue

Required

Numeric, dot decimal

products

Required

Array of {id, qty, price, name}

Example:

<script>
window.ntmData = window.ntmData || [];
window.ntmData.push({
  gdpr: "-1",
  gdprConsent: "XXXXXXXXXXXXXXXXXXXX",
  pageType: "order",
  transactionId: "order123456",
  orderValue: "2299.97",
  products: [
    { id: "prod456", qty: 1, price: "1299.99", name: "SuperLaptop 15 Pro" },
    { id: "prod789", qty: 2, price: "499.99", name: "Wireless Mouse" }
  ]
});
</script>

<!-- General Tag -->
<script>/* Insert General Tag script here */</script>

5. Key Best Practices

  • Always define window.ntmData before the General Tag.

  • Include GDPR fields if your site uses a CMP.

  • Use page-specific tags only where needed; the Generic Tag can fill gaps.

  • Match IDs, category names, and product names exactly to your catalog.

  • Test tracking after deployment to verify that data is sent correctly.


Please note that this solution is separate to The Webgains Tag, which can be managed within the Webgains platform. Please speak to your Webgains contact/account manager for more information on the solutions.