Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9b9e413575d5b801aa21b221f6a79a222f8aabb05fd4a89295822798ef4b2266
sha512=e4f4c70636aaa45f9731c3b9f5860888e80b5c19c6837950171329b409aa0808b8f86ea0ddce770df4b50fae8fa01e9d67a785bfe247086f2f37acc6984929e4
doc/privatus-analytics/Privatus_analytics/index.html
Module Privatus_analyticsSource
Prints the cookieless Privatus Analytics tracking script and the HTML attributes the tracker reads.
This library only builds HTML text. It never sends events from your server, never makes web requests, sets no cookies and reads no IP addresses or browser details.
let config = Privatus_analytics.Config.make ~site_id:"pa_YOURSITEID" ()
let head = Privatus_analytics.tag ~config ()In production it gives:
<script defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID"></script>
See the Privatus Analytics docs and the script attributes reference.
The library version, "1.0.0".
Values
type value = [ | `String of string| `Int of int| `Float of float| `Bool of bool| `List of value list| `Null
]A prop value. `Null leaves the prop out (and, in per call page props, removes a configured one).
Props as key and value pairs, for example [ ("plan", `String "pro"); ("seats", `Int 5) ].
Never put names, emails, user ids or anything else that points to one person in props. Put groups (like the plan or the role), not people.
Single page app mode. Only modes other than `Auto print a data-spa attribute.
Settings
The script tag
val tag :
?config:Config.t ->
?site_id:string ->
?script_host:string ->
?modules:string list ->
?excluded_paths:string list ->
?domains:string list ->
?spa:spa ->
?manual:bool ->
?enabled:bool ->
?extra_attributes:(string * string) list ->
?queue_stub:bool ->
?props:props ->
?props_fn:(unit -> props) ->
?nonce:string ->
unit ->
stringThe HTML for the head of your page. When there is no site id or the tag is off, it is only the queue stub (when queue_stub is on) or "". Every optional argument overrides the matching setting in config for this call.
props are merged over the configured props, and a `Null value removes one. props_fn is for framework helpers: its props sit between the configured ones and props, and it is only called when a tag prints. nonce is your Content Security Policy nonce. It goes on every script tag.
With page props or queue_stub, small inline scripts print before the tracker tag, one per line.
The official queue stub script body.
The queue stub in a <script> tag.
Page props as a JSON object that is safe inside a <script> tag, or None when no props are left. Keys follow the event prop rules. Numbers and booleans stay JSON numbers and booleans, lists stay lists (at most 30 items). <, >, &, U+2028 and U+2029 are written as < and so on.
Custom events and click maps
event_attrs ~props:[ ("format", `String "csv") ] "Export CSV" is data-privatus-event="Export CSV" data-privatus-prop-format="csv".
Put it inside a button, link or form tag. On a form the event is sent when the form is submitted. The name is trimmed and cut to 120 characters, and an empty name gives "". Prop keys are made lowercase, anything other than a-z, 0-9 and _ becomes _, and keys are cut to 64 characters. At most 30 props. Values become text (lists joined with commas) cut to 500 characters, and `Null values are left out. Every value is escaped for HTML. The attributes print even when the tag is off.
The same attributes as name and value pairs, not escaped, for HTML builders. [] for an empty name.
click_attr "pricing.cta" is data-privatus-click="pricing.cta", or "" when the name is not valid.
The click map attribute as a name and value pair, or [].
Whether a click map name is valid: 1 to 100 letters, digits or _ . : -.
Helpers
Turns attribute pairs into name="value" text with every value escaped.
Escapes ampersands, angle brackets and both kinds of quotes for HTML.
Cleans one prop key the way the tracker expects.
"/js/pa.js". A page that contains this already has the tag.
inject_html ~tag html puts tag just before the first </head> (any case). None when tag is empty, the page already has the tag, or there is no </head>. Used by framework middleware.