Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Created Docs page & added some basic documentation

Blue Mouse63675e9cf783
diff --git a/src/pages/Docs/Docs.jsx b/src/pages/Docs/Docs.jsx
index e429a5249..8c507c7df 100644
--- a/src/pages/Docs/Docs.jsx
+++ b/src/pages/Docs/Docs.jsx
@@ -1,11 +1,147 @@
-import React from 'react'
+import React, { memo, Fragment, useEffect } from 'react'
+import _map from 'lodash/map'
+import Prism from 'prismjs'
+
+import Title from 'components/Title'
+import Code from 'ui/Code'
+import {
+ umdBuildExample, trackPageView, init, trackViews,
+} from './examples'
+
+const contents = [{
+ name: 'Getting Started',
+ id: 'docs-gs',
+ content: [{
+ name: 'UMD Build',
+ id: 'docs-umd',
+ }]
+}, {
+ name: 'How to..',
+ id: 'docs-ht',
+ content: [{
+ name: 'Track pageviews',
+ id: 'docs-pv',
+ }, {
+ name: 'Track custom events',
+ id: 'docs-ce',
+ }]
+}, {
+ name: 'API',
+ id: 'docs-api',
+ content: [{
+ name: 'init',
+ id: 'docs-init',
+ }, {
+ name: 'track',
+ id: 'docs-tr',
+ }, {
+ name: 'trackViews',
+ id: 'docs-tv',
+ }]
+}]
+
+const Contents = () => (
+ <div className='lg:flex flex-1 items-start justify-center lg:order-2'>
+ <h2 className='block lg:hidden text-3xl font-bold text-gray-900 tracking-tight'>Contents:</h2>
+ <ol className='mb-10 lg:mb-0 lg:sticky lg:top-10'>
+ {_map(contents, ({ name, id, content }) => (
+ <Fragment key={id}>
+ <li className='mt-3'>
+ <a className='hover:underline text-2xl text-blue-600 font-bold' href={`#${id}`}>{name}</a>
+ </li>
+ <ol>
+ {_map(content, ({ name: cname, id: cid }) => (
+ <li key={cid}>
+ <a className='hover:underline text-lg text-blue-500 px-4' href={`#${cid}`}>{cname}</a>
+ </li>
+ ))}
+ </ol>
+ </Fragment>
+ ))}
+ </ol>
+ </div>
+)
+
+const CHeader = ({ id, name, addHr = true }) => (
+ <>
+ {addHr && (
+ <hr className='mt-10' />
+ )}
+ <h2 id={id} className='text-3xl font-bold text-gray-900 tracking-tight mt-2'>{name}</h2>
+ </>
+)
+
+const CSection = ({ id, name }) => (
+ <h3 id={id} className='text-2xl font-normal text-gray-900 tracking-tight mt-3'>{name}</h3>
+)
const Docs = () => {
+ useEffect(() => {
+ Prism.highlightAll()
+ }, [])
+
return (
- <div className='flex justify-center'>
- Docs page
- </div>
+ <Title title='Docs'>
+ <div className='bg-gray-50'>
+ <div className='w-11/12 mx-auto pb-16 pt-12 px-4 sm:px-6 lg:w-11/12 lg:px-8 lg:flex'>
+ <Contents />
+ <div className='flex-1 lg:order-1'>
+ <h1 className='text-4xl font-extrabold text-gray-900 tracking-tight'>Documentation</h1>
+
+ <CHeader id='docs-gs' name='Getting Started' addHr={false} />
+ <CSection id='docs-umd' name='UMD Build' />
+ <Code text={umdBuildExample} language='html' />
+
+ <CHeader id='docs-ht' name='How to..' />
+ <CSection id='docs-pv' name='Track pageviews' />
+ <p className='text-lg text-gray-900 tracking-tight'>
+ Swetrix.js tracking script provides a way to collect a page view event once the page has loaded.<br />
+ This can be accomplished via calling the <span className='font-bold'>trackViews()</span> function:<br />
+ </p>
+ <Code text={trackPageView} language='javascript' />
+
+ <CHeader id='docs-api' name='API' />
+
+ <CSection id='docs-init' name='init' />
+ <p className='text-lg text-gray-900 tracking-tight'>
+ This fuction is used to initialise the analytics.<br />
+ Basically you're letting the script know which project do you want to use it with, as well as specifying your custom parameters if needed.
+ </p>
+ <Code text={init} language='javascript' />
+
+ <CSection id='docs-tr' name='track' />
+ <p className='text-lg text-gray-900 tracking-tight'>
+ This section is not ready yet..
+ </p>
+
+ <CSection id='docs-tv' name='trackViews' />
+ <p className='text-lg text-gray-900 tracking-tight'>
+ Calling trackViews will result in sending the data about the user to our servers.<br />
+ Such data will include the next params if available:<br />
+ <div className='mb-5'>
+ <ul className='ml-10'>
+ <li><b>pid</b> - the unique Project ID request is related to.</li>
+ <li><b>ev</b> ('pageviews') - the name of the event. Basically, the <i>trackViews</i> does the same job as <a href='#docs-tr'>track</a>, but with already predefined parameters.</li>
+ <li><b>lc</b> - users locale (e.g. en_US or uk_UA).</li>
+ <li><b>tz</b> - users timezone (e.g. Europe/Helsinki).</li>
+ <li><b>ref</b> - the URL of the previous webpage from which a page was opened.</li>
+ <li><b>so</b> - the page source ('ref' | 'source' | 'utm_source' GET param).</li>
+ <li><b>me</b> - UTM medium ('utm_medium' GET param).</li>
+ <li><b>ca</b> - UTM campaign ('utm_campaign' GET param).</li>
+ <li><b>pg</b> - the page user currently views (e.g. /hello)</li>
+ </ul>
+ </div>
+ On the server side we also gather users IP Address and User Agent.<br />
+ This data is used to detect whether the page view is unique or not.<br />
+ <b>We DO NOT store neither IP Address or User Agent as a raw strings</b>, such data is stored as a salted hash for no longer than 30 minutes or 12:00 AM UTC, whatever happens first.<br />
+ After this timeframe the identifiable data is forever deleted from our servers.
+ </p>
+ <Code text={trackViews} language='javascript' />
+ </div>
+ </div>
+ </div>
+ </Title>
)
}
-export default Docs
+export default memo(Docs)
diff --git a/src/pages/Docs/examples.js b/src/pages/Docs/examples.js
new file mode 100644
index 000000000..dffa1a129
--- /dev/null
+++ b/src/pages/Docs/examples.js
@@ -0,0 +1,35 @@
+export const umdBuildExample = `<script src="./analytics_script/dist/analytics.umd.min.js" defer></script>
+
+<script>
+ document.addEventListener('DOMContentLoaded', () => {
+ // Initialising the script with the Project ID
+ // you can find in the dashboard
+ analytics.init('YOUR_PROJECT_ID')
+
+ // Tracking page views
+ analytics.trackViews()
+ })
+</script>
+`
+
+export const trackPageView = `analytics.trackViews()`
+
+export const init = `analytics.init('YOUR_PROJECT_ID', {
+ // When set to true, all tracking logs will be
+ // printed to console and localhost events will be sent to server.
+ debug: false,
+
+ // When set to true, the tracking library won't send any data to server.
+ // Useful for development purposes when this value is set based on '.env' var.
+ disabled: false,
+
+ // By setting this flag to true, we will not collect ANY kind of data
+ // about the user with the DNT setting.
+ // This setting is not true by default because our service
+ // anonymises all incoming data and does not pass it on
+ // to any third parties under any circumstances
+ respectDNT: false,
+})
+`
+
+export const trackViews = `analytics.trackViews()`