Show Referrers in TelemetryDeck for Web with a TopN TQL Query

The current TelemetryDeck for web setup guide (version of 2023-12-01) is quite simple. Insert this into your HTML, and you’re set:

<script
  src="https://cdn.telemetrydeck.com/websdk/telemetrydeck.min.js"
  data-app-id="<YOUR APP ID>"
></script>

From that point onward, you’ll be collecting signals per web site hit. Internally, the signal’s type is "type":"pageview". These signals will include all the usual suspects: browser, os and version, url (the page that was visited), and also referrer (where visitors may have come from, following a link).

Update 2023-12-21: Attention, attention! I found a much simpler way using the web UI to get the same result. Includes a video tutorial, too! Check it out. It’s better, I promise.

The fun part of web analytics, in my opinion, is to see where people come from. Is there any new blog that links to mine? Someone I might want to follow back, perhaps?

This is an Insight you need to add to your dashboard. The docs for this feature are good, so check these out.

  1. Create a new Insight,
  2. Name it “Referrers” or “Link Sources”,
  3. Use the “Advanced Query” insight type.

To get on overview of the top, say, 100 referrers, here’s the TQL code you need:

{
  "dataSource": "telemetry-signals",
  "queryType": "topN",
  "threshold": 100,
  "granularity": "month",
  "dimension": {
    "dimension": "referrer",
    "outputName": "Referrer/Link Source",
    "outputType": "STRING",
    "type": "default"
  },
  "aggregations": [
    {
      "name": "Count",
      "type": "count"
    }
  ],
  "metric": {
    "metric": "Count",
    "type": "numeric"
  }
}

Because the referrer can also be your own site, I added filters. Put this into the JSON object, e.g. after "metric'. (Doesn’t matter where, in the end, because JSON isn’t stored in a sorted fashion and next time you visit the insight editor.)

  "filter": {
    "fields": [
      {
        "dimension": "referrer",
        "pattern": ".+",
        "type": "regex"
      },
      {
        "field": {
          "dimension": "referrer",
          "pattern": "/(forum\\.)?zettelkasten\\.de/",
          "type": "regex"
        },
        "type": "not"
      }
    ],
    "type": "and"
  }

This ignores the empty referrer (e.g. bookmarks, direct links from other apps) and the domains zettelkasten.de and forum.zettelkasten.de, wrapped in a pair of “/” to not filter out Google translate subdomains starting like “zettelkasten.de.goog…”. That reduces the noise quite a lot.

Maybe excluding search engines and translations pages also makes sense to really highlight organic traffic sources.