Tracking code recipes

Replace example.com/Ab3xK9 with the tracking code shown in your website's settings. The files script.manual.min.js and tracker.js are the same script. The first one waits for you to send each pageview, the second one sends it by itself.

Quick install

Put this in the <head> of your site. If you use a caching or minifying plugin (WP Rocket, W3 Total Cache, LiteSpeed), exclude our script from it.

<script defer data-domain="example.com/Ab3xK9" src="https://weblytic360.com/script.manual.min.js"></script>
<script>
  window.weblytic360 = window.weblytic360 || function () { (window.weblytic360.q = window.weblytic360.q || []).push(arguments); };
  weblytic360('pageview');
</script>

Custom dimensions

Send extra information with a pageview, such as the author or the category of an article. It shows up in Events → Custom data. Use only letters, numbers and underscores in the names.

<script defer data-domain="example.com/Ab3xK9" src="https://weblytic360.com/script.manual.min.js"></script>
<script>
  window.weblytic360 = window.weblytic360 || function () { (window.weblytic360.q = window.weblytic360.q || []).push(arguments); };
  weblytic360('pageview', { props: { article_id: 123456, author_id: 101, article_title: "example title" } });
</script>

Custom events

Fire an event on a click or any action. This does not replace the main script: add it as well. Use only letters, numbers and underscores in the event name.

<script>
  document.addEventListener('DOMContentLoaded', function () {
    var button = document.getElementById('myButton'); // the id of your button
    button.addEventListener('click', function () {
      if (typeof weblytic360 !== 'undefined') {
        weblytic360('myEventWithProps', { props: { prop1: 'content1', prop2: 'content2' } }); // with properties
        weblytic360('myEvent'); // without properties
      }
    });
  });
</script>

AMP pages

Put this inside the <body> of your AMP page and replace TITLE with the real title. Every name under "p" becomes a custom dimension. SOURCE_URL must belong to your website.

<amp-analytics>
  <script type="application/json">
  {
    "requests": { "event": "https://api.weblytic360.com/api/events/amp" },
    "extraUrlParams": {
      "r": "${documentReferrer}",
      "u": "SOURCE_URL",
      "w": 400,
      "d": "example.com/Ab3xK9"
    },
    "triggers": {
      "trackPageview": {
        "on": "visible",
        "request": "event",
        "extraUrlParams": {
          "n": "pageview",
          "p": {
            "article_title": "TITLE"
          }
        }
      }
    },
    "transport": { "beacon": true, "xhrpost": true, "image": false, "useBody": false }
  }
  </script>
</amp-analytics>

WordPress

Add this to your theme's header.php (before </head>). PHP code must be allowed to run, and WordPress should be version 6.0 or newer. It sends the author, article and category with every post.

<script defer data-domain="example.com/Ab3xK9" src="https://weblytic360.com/script.manual.min.js"></script>
<script>
  window.weblytic360 = window.weblytic360 || function () { (window.weblytic360.q = window.weblytic360.q || []).push(arguments); };
<?php if (is_single()) { ?>
  weblytic360('pageview', { props: {
    author_id: <?php echo get_the_author_meta('ID', get_post_field('post_author')); ?>,
    author_name: "<?php echo esc_js(get_the_author_meta('nicename', get_post_field('post_author'))); ?>",
    article_id: <?php echo get_the_ID(); ?>,
    article_title: "<?php echo esc_js(get_the_title()); ?>",
    category_name: "<?php $c = get_the_category(); echo esc_js($c ? $c[0]->name : ''); ?>",
    published_date: "<?php echo get_the_date('Y-m-d'); ?>"
  }});
<?php } else { ?>
  weblytic360('pageview');
<?php } ?>
</script>

WordPress AMP

With the Ad Inserter plugin you can place this block in AMP pages (before the end of the body). With AMP for WP, use the generic AMP code in its analytics settings.

<?php if (function_exists('amp_is_request') && amp_is_request()) { $c = get_the_category(); ?>
<amp-analytics>
  <script type="application/json">
  {
    "requests": { "event": "https://api.weblytic360.com/api/events/amp" },
    "extraUrlParams": { "r": "${documentReferrer}", "u": "SOURCE_URL", "w": 400, "d": "example.com/Ab3xK9" },
    "triggers": {
      "trackPageview": {
        "on": "visible",
        "request": "event",
        "extraUrlParams": {
          "n": "pageview",
          "p": {
            "author_name": "<?php echo esc_js(get_the_author_meta('nicename', get_post_field('post_author'))); ?>",
            "article_id": "<?php echo get_the_ID(); ?>",
            "article_title": "<?php echo esc_js(get_the_title()); ?>",
            "category_name": "<?php echo esc_js($c ? $c[0]->name : ''); ?>"
          }
        }
      }
    },
    "transport": { "beacon": true, "xhrpost": true, "image": false, "useBody": false }
  }
  </script>
</amp-analytics>
<?php } ?>

Your own page address

Merge several addresses into one (a canonical address, or addresses with ids in them) by giving your own address with u. Keep window.location.search at the end so campaign tags (UTM) are still read.

<script defer data-domain="example.com/Ab3xK9" src="https://weblytic360.com/script.manual.min.js"></script>
<script>
  window.weblytic360 = window.weblytic360 || function () { (window.weblytic360.q = window.weblytic360.q || []).push(arguments); };
  weblytic360('pageview', { u: "https://example.com/your-custom-url" + window.location.search });
</script>

Several websites

Give a comma separated list of tracking codes. Every pageview and event is sent to all of them.

<script defer data-domain="example.com/Ab3xK9,otherdomain.com/Cd4yL8,third.com/Ef5zM1" src="https://weblytic360.com/script.manual.min.js"></script>
<script>
  window.weblytic360 = window.weblytic360 || function () { (window.weblytic360.q = window.weblytic360.q || []).push(arguments); };
  weblytic360('pageview');
</script>