文档
浏览文档

Install Privatus Analytics with Google Tag Manager

Load the Privatus Analytics tracker from a Google Tag Manager Custom HTML tag, set consent settings, send events from GTM triggers and avoid double counting.

查看 Markdown

If your site already loads tags through Google Tag Manager, you can load Privatus Analytics from it. Adding the snippet directly to your pages is still more reliable: GTM itself is blocked by many ad blockers.

Custom HTML tag#

  1. In your container go to Tags → New → Tag configuration → Custom HTML.
  2. Paste:
html
   <script>
     (function () {
       var s = document.createElement('script');
       s.defer = true;
       s.src = 'https://privatusstats.com/js/pa.js';
       s.setAttribute('data-site', 'pa_YOURSITEID');
       s.setAttribute('data-modules', 'engage,auto,vitals,clicks,ask');
       document.head.appendChild(s);
     })();
   </script>
  1. Trigger: Initialization - All Pages (or All Pages).
  2. Save, preview, and Submit to publish.

The tag creates the script element itself so the data- attributes are sure to reach the tracker, which reads all of its settings from them. Add any other attribute with another s.setAttribute(…) line. Site settings → Tracking shows this code with your site id filled in, under the Google Tag Manager tab.

Privatus Analytics sets no cookies and reads nothing from the device, so in GTM's Consent settings for the tag you can choose No additional consent required if that matches your legal assessment. See Privacy & compliance.

Sending events from GTM#

Create more Custom HTML tags that call the JavaScript API, fired by your GTM triggers:

html
<script>
  window.privatus && privatus.track('Contact form', { form: {{Form ID}} });
</script>

{{Form ID}} here is a GTM variable. Only send values that contain no personal data.

Single-page apps#

Don't fire the tag again on "History change" triggers. The tracker already follows history.pushState navigations, and loading it a second time counts pages twice. See SPA double counting.