Installation guides
Google Tag Manager
Load ProductLense from a Custom HTML tag in Google Tag Manager that fires on all pages.
If your site's scripts are managed in Google Tag Manager, load ProductLense from a Custom HTML tag that fires on every page. Use the small loader below rather than pasting the plain script tag: it creates the ProductLense script element and sets data-site explicitly, so the attribute survives however Tag Manager injects the tag.
Create the tag
- Copy your site id from Settings → Sites in the ProductLense dashboard.
- In Tag Manager, open Tags → New → Tag Configuration → Custom HTML.
- Paste the snippet, replacing
SITE_ID. Leave Support document.write turned off; it is not needed. - Under Triggering, choose All Pages (or Initialization - All Pages).
- Save, then Submit and publish the container.
<script>
(function () {
window.productlense = window.productlense || function () {
(window.productlense.q = window.productlense.q || []).push(arguments);
};
var s = document.createElement('script');
s.defer = true;
s.src = 'https://api.productlense.app/a.js';
s.setAttribute('data-site', 'SITE_ID');
document.head.appendChild(s);
})();
</script>Set other attributes the same way, for example s.setAttribute('data-exclude', '/admin/*');. See the script attributes.
Custom events and identify from Tag Manager
Fire events from another Custom HTML tag on the trigger you already use, such as a form submission or a dataLayer event:
<script>
window.productlense('event', 'Signup', { plan: {{DLV - plan}} });
</script><script>
if ({{DLV - user_id}}) window.productlense('identify', String({{DLV - user_id}}));
</script>{{DLV - plan}} and {{DLV - user_id}} stand for Data Layer Variables you define in the container. The queue stub in the loader keeps these calls until the ProductLense script has loaded. Use the same user id you store on the customer in your billing provider; see how payments are attributed.
Verify your installation
- Publish the container (Preview mode works too), then open your site in a normal browser window.
- Open the Live page in the ProductLense dashboard. Your visit appears within a few seconds.
- In the browser's developer tools, the Network tab shows a request for
https://api.productlense.app/a.jsand aPOSTtohttps://api.productlense.app/api/ewith status204.
Nothing is sent from localhost unless you add s.setAttribute('data-dev', 'true');. Ad blockers in your own browser may block the request. If the visit does not appear, follow Verify your installation.