analytics/Plausible.Ingestion.Source.html
github-merge-queue[bot] ed60dddd9d deploy: 4d9ea15e9e
2024-11-21 11:18:46 +00:00

449 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.31.1">
<meta name="project" content="Plausible v0.0.1">
<title>Plausible.Ingestion.Source — Plausible v0.0.1</title>
<link rel="stylesheet" href="dist/html-elixir-FM2CSD74.css" />
<script src="dist/handlebars.runtime-NWIB6V2M.js"></script>
<script src="dist/handlebars.templates-43PMFBC7.js"></script>
<script src="dist/sidebar_items-DD84C8DF.js"></script>
<script src="docs_config.js"></script>
<script async src="dist/html-L4O5OK2K.js"></script>
</head>
<body data-type="modules" class="page-module">
<script>
try {
var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}');
if (settings.theme === 'dark' ||
((settings.theme === 'system' || settings.theme == null) &&
window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
document.body.classList.add('dark')
}
} catch (error) { }
</script>
<div class="main">
<button id="sidebar-menu" class="sidebar-button sidebar-toggle" aria-label="toggle sidebar" aria-controls="sidebar">
<i class="ri-menu-line ri-lg" title="Collapse/expand sidebar"></i>
</button>
<div class="background-layer"></div>
<nav id="sidebar" class="sidebar">
<div class="sidebar-header">
<div class="sidebar-projectInfo">
<a href="readme.html" class="sidebar-projectImage">
<img src="assets/logo.png" alt="Plausible" />
</a>
<div>
<a href="readme.html" class="sidebar-projectName" translate="no">
Plausible
</a>
<div class="sidebar-projectVersion" translate="no">
v0.0.1
</div>
</div>
</div>
<ul id="sidebar-listNav" class="sidebar-listNav" role="tablist">
<li>
<button id="extras-list-tab-button" role="tab" data-type="extras" aria-controls="extras-tab-panel" aria-selected="true" tabindex="0">
Pages
</button>
</li>
<li>
<button id="modules-list-tab-button" role="tab" data-type="modules" aria-controls="modules-tab-panel" aria-selected="false" tabindex="-1">
Modules
</button>
</li>
<li>
<button id="tasks-list-tab-button" role="tab" data-type="tasks" aria-controls="tasks-tab-panel" aria-selected="false" tabindex="-1">
<span translate="no">Mix</span> Tasks
</button>
</li>
</ul>
</div>
<div id="extras-tab-panel" class="sidebar-tabpanel" role="tabpanel" aria-labelledby="extras-list-tab-button">
<ul id="extras-full-list" class="full-list"></ul>
</div>
<div id="modules-tab-panel" class="sidebar-tabpanel" role="tabpanel" aria-labelledby="modules-list-tab-button" hidden>
<ul id="modules-full-list" class="full-list"></ul>
</div>
<div id="tasks-tab-panel" class="sidebar-tabpanel" role="tabpanel" aria-labelledby="tasks-list-tab-button" hidden>
<ul id="tasks-full-list" class="full-list"></ul>
</div>
</nav>
<main class="content">
<output role="status" id="toast"></output>
<div class="content-outer">
<div id="content" class="content-inner">
<div class="top-search">
<div class="search-settings">
<form class="search-bar" action="search.html">
<label class="search-label">
<span class="sr-only">Search documentation of Plausible</span>
<input name="q" type="text" class="search-input" placeholder="Search Documentation (press /)" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
</label>
<button type="submit" class="search-button" aria-label="Submit Search">
<i class="ri-search-2-line ri-lg" aria-hidden="true" title="Submit search"></i>
</button>
<button type="button" tabindex="-1" class="search-close-button" aria-hidden="true">
<i class="ri-close-line ri-lg" title="Cancel search"></i>
</button>
</form>
<div class="autocomplete">
</div>
<button class="icon-settings display-settings">
<i class="ri-settings-3-line"></i>
<span class="sr-only">Settings</span>
</button>
</div>
</div>
<h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L1" title="View Source" class="icon-action" rel="help">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
<span translate="no">Plausible.Ingestion.Source</span>
<small class="app-vsn" translate="no">(Plausible v0.0.1)</small>
</h1>
<section id="moduledoc">
<p>Resolves the <code class="inline">source</code> dimension from a combination of <code class="inline">referer</code> header and either <code class="inline">utm_source</code>, <code class="inline">source</code>, or <code class="inline">ref</code> query parameter.</p>
</section>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<span class="text">Summary</span>
</h1>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#find_mapping/1" translate="no">find_mapping(source)</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#format_referrer/1" translate="no">format_referrer(referrer)</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#init/0" translate="no">init()</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#paid_source?/1" translate="no">paid_source?(source)</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#paid_sources/0" translate="no">paid_sources()</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#parse/1" translate="no">parse(ref)</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#resolve/1" translate="no">resolve(request)</a>
</div>
<div class="summary-synopsis"><p>Resolves the source of a session based on query params and the <code class="inline">Referer</code> header.</p></div>
</div>
</div>
</section>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<span class="text">Functions</span>
</h1>
<div class="functions-list">
<section class="detail" id="find_mapping/1">
<div class="detail-header">
<a href="#find_mapping/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">find_mapping(source)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L110" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
</section>
</section>
<section class="detail" id="format_referrer/1">
<div class="detail-header">
<a href="#format_referrer/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">format_referrer(referrer)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L119" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
</section>
</section>
<section class="detail" id="init/0">
<div class="detail-header">
<a href="#init/0" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">init()</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L18" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
</section>
</section>
<section class="detail" id="paid_source?/1">
<div class="detail-header">
<a href="#paid_source?/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">paid_source?(source)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L44" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
</section>
</section>
<section class="detail" id="paid_sources/0">
<div class="detail-header">
<a href="#paid_sources/0" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">paid_sources()</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L40" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
</section>
</section>
<section class="detail" id="parse/1">
<div class="detail-header">
<a href="#parse/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">parse(ref)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L96" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
</section>
</section>
<section class="detail" id="resolve/1">
<div class="detail-header">
<a href="#resolve/1" class="detail-link" title="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature" translate="no">resolve(request)</h1>
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/ingestion/source.ex#L80" class="icon-action" rel="help" title="View Source">
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Resolves the source of a session based on query params and the <code class="inline">Referer</code> header.</p><p>When a query parameter like <code class="inline">utm_source</code> is present, it will be prioritized over the <code class="inline">Referer</code> header. When the URL does not contain a source tag, we fall
back to using <code class="inline">Referer</code> to determine the source. This module also takes care of certain transformations to make the data more useful for the user:</p><ol><li>The RefInspector library is used to categorize referrers into &quot;known&quot; sources. For example, when the referrer is google.com or google.co.uk,
it will always be stored as &quot;Google&quot; which is more useful for marketers.</li><li>On top of the standard RefInspector behaviour, we also keep a list of <code class="inline">custom_sources.json</code> which extends it with referrers that we have seen in the wild.
For example, Wikipedia has many domains that need to be combined into a single known source. These could all in theory be <a href="https://github.com/snowplow-referer-parser/referer-parser">upstreamed</a>.</li><li>When a known source is supplied in utm_source (or source, ref) query parameter, we merge it with our known sources in a case-insensitive manner.</li><li>Our list of <code class="inline">custom_sources.json</code> also contains some commonly used utm_source shorthands for certain sources. URL tagging is a mess, and we can never do it
perfectly, but at least we're making an effort for the most commonly used ones. For example, <code class="inline">ig -&gt; Instagram</code> and <code class="inline">adwords -&gt; Google</code>.</li></ol><h3 id="resolve/1-examples" class="section-heading">
<a href="#resolve/1-examples" class="hover-link">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<span class="text">Examples:</span>
</h3>
<p> iex&gt; alias Plausible.Ingestion.{Source, Request}
iex&gt; base_request = %Request{uri: URI.parse(&quot;<a href="https://plausible.io%22)%7D">https://plausible.io&quot;)}</a>
iex&gt; Source.resolve(%{base_request | referrer: &quot;<a href="https://google.com%22%7D">https://google.com&quot;}</a>) # Known referrer from RefInspector
&quot;Google&quot;
iex&gt; Source.resolve(%{base_request | query_params: %{&quot;utm_source&quot; =&gt; &quot;google&quot;}}) # Known source from RefInspector supplied as downcased utm_source by user
&quot;Google&quot;
iex&gt; Source.resolve(%{base_request | query_params: %{&quot;utm_source&quot; =&gt; &quot;GOOGLE&quot;}}) # Known source from RefInspector supplied as uppercased utm_source by user
&quot;Google&quot;
iex&gt; Source.resolve(%{base_request | referrer: &quot;<a href="https://en.m.wikipedia.org%22%7D">https://en.m.wikipedia.org&quot;}</a>) # Known referrer from custom_sources.json
&quot;Wikipedia&quot;
iex&gt; Source.resolve(%{base_request | query_params: %{&quot;utm_source&quot; =&gt; &quot;wikipedia&quot;}}) # Known source from custom_sources.json supplied as downcased utm_source by user
&quot;Wikipedia&quot;
iex&gt; Source.resolve(%{base_request | query_params: %{&quot;utm_source&quot; =&gt; &quot;ig&quot;}}) # Known utm_source from custom_sources.json
&quot;Instagram&quot;
iex&gt; Source.resolve(%{base_request | referrer: &quot;<a href="https://www.markosaric.com%22%7D">https://www.markosaric.com&quot;}</a>) # Unknown source, it is just stored as the domain name
&quot;markosaric.com&quot;</p>
</section>
</section>
</div>
</section>
<footer class="footer">
<p>
<span class="line">
<button class="a-main footer-button display-quick-switch" title="Search HexDocs packages">
Search HexDocs
</button>
<a href="Plausible.epub" title="ePub version">
Download ePub version
</a>
</span>
</p>
<p class="built-using">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener" translate="no">ExDoc</a> (v0.31.1) for the
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>
</p>
</footer>
</div>
</div>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad: true})</script>
</body>
</html>