@enodo/butterfly-tracker 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # butterfly-tracker
2
2
 
3
3
  Cookieless first-party audience tracker for **Enodo Butterfly** sites. One tiny
4
- `POST {tracker}/h` per page view; the Butterfly CMS turns them into realtime stats,
5
- trending / rising / top posts (`sort=trending` on the public API) and Performances.
4
+ `POST {tracker}/h` per page view; the Butterfly CMS turns them into realtime stats and
5
+ trending / rising / top posts (`sort=trending` on the public API).
6
6
 
7
7
  - No cookie, no localStorage, no identifier, credentials omitted: built for the CNIL
8
8
  audience-measurement exemption, so it does **not** wait for consent.
@@ -40,12 +40,17 @@ same URL are not sent.
40
40
  ## Without a bundler
41
41
 
42
42
  ```html
43
- <script defer src="https://cdn.jsdelivr.net/npm/@enodo/butterfly-tracker/dist/butterfly-tracker.min.js"
44
- data-url="https://t.example.com" data-type="post" data-id="123"></script>
43
+ <script
44
+ defer
45
+ src="https://cdn.jsdelivr.net/npm/@enodo/butterfly-tracker/dist/butterfly-tracker.min.js"
46
+ data-url="https://t.example.com"
47
+ data-type="post"
48
+ data-id="123"
49
+ ></script>
45
50
  ```
46
51
 
47
52
  Sends one hit on load (`data-type` defaults to `page`, `data-auto="false"` to skip) and
48
- exposes `window.ButterflyTracker`.
53
+ exposes `window.btfTrack` for manual hits: `btfTrack({ t: 'post', id: '123' })`.
49
54
 
50
55
  ## Without JavaScript
51
56
 
@@ -54,8 +59,13 @@ query string on `GET /h.gif`:
54
59
 
55
60
  ```html
56
61
  <noscript>
57
- <img src="https://t.example.com/h.gif?t=post&id=123" alt="" width="1" height="1"
58
- style="position:absolute">
62
+ <img
63
+ src="https://t.example.com/h.gif?t=post&id=123"
64
+ alt=""
65
+ width="1"
66
+ height="1"
67
+ style="position:absolute"
68
+ />
59
69
  </noscript>
60
70
  ```
61
71
 
@@ -65,13 +75,13 @@ page cannot read `document.referrer`, so no `e` / `r` is sent.
65
75
 
66
76
  ## Hit
67
77
 
68
- | key | meaning |
69
- | --- | --- |
70
- | `t` | page type: post, page, category, tag, author, home, search, or any site type |
71
- | `id` | id of the content in the Butterfly API (post, category, term, author) |
72
- | `tx` | taxonomy id of a term page |
73
- | `pi` | page index |
74
- | `q`, `n` | search query, number of results |
75
- | `p` | property id, only on a shared tracker host |
76
- | `e` | entry: `1` on the first hit after a page load (set by the tracker) |
77
- | `r` | referrer hostname of the entry hit, never the full URL (set by the tracker) |
78
+ | key | meaning |
79
+ | -------- | ---------------------------------------------------------------------------- |
80
+ | `t` | page type: post, page, category, tag, author, home, search, or any site type |
81
+ | `id` | id of the content in the Butterfly API (post, category, term, author) |
82
+ | `tx` | taxonomy id of a term page |
83
+ | `pi` | page index |
84
+ | `q`, `n` | search query, number of results |
85
+ | `p` | property id, only on a shared tracker host |
86
+ | `e` | entry: `1` on the first hit after a page load (set by the tracker) |
87
+ | `r` | referrer hostname of the entry hit, never the full URL (set by the tracker) |
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{var I=Object.defineProperty,v=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var H=(t,e,n)=>e in t?I(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e)=>{for(var n in e||(e={}))w.call(e,n)&&H(t,n,e[n]);if(l)for(var n of l(e))U.call(e,n)&&H(t,n,e[n]);return t},L=(t,e)=>v(t,B(e));var O=(t,e)=>{var n={};for(var r in t)w.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&l)for(var r of l(t))e.indexOf(r)<0&&U.call(t,r)&&(n[r]=t[r]);return n};function g(t){if(!t)return null;let e;try{e=new URL(t).hostname.toLowerCase()}catch(a){return null}let n=/^(\d+)\.pubbtf\.eno\.do$/.exec(e);if(n)return`https://${n[1]}.tbtf.eno.do`;let r=/^api([a-z0-9-]*)\.(.+\..+)$/.exec(e);return r?`https://t${r[1]}.${r[2]}`:null}function q(t,e){return t==="off"||t==="false"?null:t?t.replace(/\/+$/,""):g(e)}function m(t,e={}){var d,c;let n=(d=e.typeKeys)!=null?d:["content.type"],r=(c=e.postTypes)!=null?c:["post"],a=n.map(p=>t[p]).find(p=>typeof p=="string"&&p);if(typeof a!="string")return null;let o=t["content.id"],s=typeof o=="string"&&o||typeof o=="number"?String(o):void 0,u={t:r.includes(a)&&s!==void 0&&s!=="0"?"post":a};return s!==void 0&&(u.id=s),typeof t["content.taxonomy"]=="string"&&(u.tx=t["content.taxonomy"]),typeof t["page.index"]=="number"&&(u.pi=t["page.index"]),typeof t["page.query"]=="string"&&(u.q=t["page.query"]),typeof t["page.results"]=="number"&&(u.n=t["page.results"]),u}function A(t){let e=t!=null?t:typeof document=="undefined"?"":String(document.referrer||"");if(e)try{return new URL(e).hostname.toLowerCase()||void 0}catch(n){return}}function F(t,e){let n=typeof navigator=="undefined"?void 0:navigator;if(typeof(n==null?void 0:n.sendBeacon)=="function")try{if(n.sendBeacon(t,new Blob([e],{type:"text/plain"})))return!0}catch(r){}return typeof fetch=="function"?(fetch(t,{method:"POST",body:e,keepalive:!0,credentials:"omit",headers:{"Content-Type":"text/plain"}}).catch(()=>{}),!0):!1}function h(t={}){let e=t.enabled===!1?null:q(t.url,t.apiUrl),n,r=!1;function a(o){var s;try{if(!e||typeof window=="undefined"||((s=o.pi)!=null?s:1)>1)return!1;let f=o,{e:u,r:d}=f,c=O(f,["e","r"]),p=t.propertyId?L(y({},c),{p:t.propertyId}):y({},c),T=`${window.location.href}
2
- ${JSON.stringify(p)}`;if(T===n)return!1;if(n=T,!r){p.e=1;let b=A();b&&(p.r=b)}let k=F(`${e}/h`,JSON.stringify(p));return k&&(r=!0),k}catch(u){return!1}}return{url:e,hit:a,pageview(o,s){let f=m(o,s);return f?a(f):!1}}}var x=document.currentScript,$,i=($=x==null?void 0:x.dataset)!=null?$:{},S=h({url:i.url,apiUrl:i.apiUrl,propertyId:i.property?parseInt(i.property,10):void 0});window.ButterflyTracker={tracker:S,createTracker:h,toHit:m,trackerUrlFromApiUrl:g};if(i.auto!=="false"){let t={t:i.type||"page"};i.id&&(t.id=i.id),i.taxonomy&&(t.tx=i.taxonomy),S.hit(t)}})();
1
+ "use strict";(()=>{var I=Object.defineProperty,v=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var w=(t,e,n)=>e in t?I(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e)=>{for(var n in e||(e={}))U.call(e,n)&&w(t,n,e[n]);if(l)for(var n of l(e))O.call(e,n)&&w(t,n,e[n]);return t},L=(t,e)=>v(t,B(e));var $=(t,e)=>{var n={};for(var r in t)U.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&l)for(var r of l(t))e.indexOf(r)<0&&O.call(t,r)&&(n[r]=t[r]);return n};function g(t){if(!t)return null;let e;try{e=new URL(t).hostname.toLowerCase()}catch(u){return null}let n=/^(\d+)\.pubbtf\.eno\.do$/.exec(e);if(n)return`https://${n[1]}.tbtf.eno.do`;let r=/^api([a-z0-9-]*)\.(.+\..+)$/.exec(e);return r?`https://t${r[1]}.${r[2]}`:null}function q(t,e){return t==="off"||t==="false"?null:t?t.replace(/\/+$/,""):g(e)}function m(t,e={}){var d,f;let n=(d=e.typeKeys)!=null?d:["content.type"],r=(f=e.postTypes)!=null?f:["post"],u=n.map(p=>t[p]).find(p=>typeof p=="string"&&p);if(typeof u!="string")return null;let o=t["content.id"],s=typeof o=="string"&&o||typeof o=="number"?String(o):void 0,a={t:r.includes(u)&&s!==void 0&&s!=="0"?"post":u};return s!==void 0&&(a.id=s),typeof t["content.taxonomy"]=="string"&&(a.tx=t["content.taxonomy"]),typeof t["page.index"]=="number"&&(a.pi=t["page.index"]),typeof t["page.query"]=="string"&&(a.q=t["page.query"]),typeof t["page.results"]=="number"&&(a.n=t["page.results"]),a}function A(t){let e=t!=null?t:typeof document=="undefined"?"":String(document.referrer||"");if(e)try{return new URL(e).hostname.toLowerCase()||void 0}catch(n){return}}function F(t,e){let n=typeof navigator=="undefined"?void 0:navigator;if(typeof(n==null?void 0:n.sendBeacon)=="function")try{if(n.sendBeacon(t,new Blob([e],{type:"text/plain"})))return!0}catch(r){}return typeof fetch=="function"?(fetch(t,{method:"POST",body:e,keepalive:!0,credentials:"omit",headers:{"Content-Type":"text/plain"}}).catch(()=>{}),!0):!1}function h(t={}){let e=t.enabled===!1?null:q(t.url,t.apiUrl),n,r=!1;function u(o){var s;try{if(!e||typeof window=="undefined"||((s=o.pi)!=null?s:1)>1)return!1;let c=o,{e:a,r:d}=c,f=$(c,["e","r"]),p=t.propertyId?L(y({},f),{p:t.propertyId}):y({},f),k=`${window.location.href}
2
+ ${JSON.stringify(p)}`;if(k===n)return!1;if(n=k,!r){p.e=1;let H=A();H&&(p.r=H)}let x=F(`${e}/h`,JSON.stringify(p));return x&&(r=!0),x}catch(a){return!1}}return{url:e,hit:u,pageview(o,s){let c=m(o,s);return c?u(c):!1}}}var T=document.currentScript,S,i=(S=T==null?void 0:T.dataset)!=null?S:{},b=h({url:i.url,apiUrl:i.apiUrl,propertyId:i.property?parseInt(i.property,10):void 0});window.btfTrack=Object.assign(t=>b.hit(t),{tracker:b,createTracker:h,toHit:m,trackerUrlFromApiUrl:g});if(i.auto!=="false"){let t={t:i.type||"page"};i.id&&(t.id=i.id),i.taxonomy&&(t.tx=i.taxonomy),b.hit(t)}})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enodo/butterfly-tracker",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "Cookieless first-party audience tracker for Enodo Butterfly sites (pageview hits, no cookie, no storage)",
6
6
  "author": "Jerome Musialak <jerome@eno.do>",