📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added the extension SDK docs
Blue Mouse1888572e3179
diff --git a/docs/ext-sdk-faq.md b/docs/ext-sdk-faq.mdnew file mode 100644index 000000000..f5987dab2--- /dev/null+++ b/docs/ext-sdk-faq.md@@ -0,0 +1,32 @@+---+title: Extensions SDK FAQ+slug: /sdk-faq+---++## How to test an extension?+So, you have written your custom extension and want to test it. Cool!++At the moment, the marketplace and extensions are in beta, so for now we provide 1 way to test your extensions: to do so, you need to download and locally run the [Swetrix frontend repository](https://github.com/Swetrix/swetrix-fe).++Once you've got it up and running, you can drop your extension into the public/assets directory, then manually add a link to your extension in the `src/pages/Project/View/ViewProject.jsx` file.++The result should be something like this:+```javascript+// this useEffect hook is located around line 300 in ViewProject.jsx+useEffect(() => {+ let sdk = null+ if (true) {+ sdk = new SwetrixSDK([{+ id: 'some-test-ext-id',+ cdnURL: 'http://localhost:3000/assets/test_extension.js'+ }], {+ debug: isDevelopment,+ }, {+ // ....leave the following code unmodified+```++We are currently working on draft extensions so you can upload your beta extensions to the marketplace and test them on the production version of Swetrix.+As soon as this functionality is implemented, we will update this section of the documentation.++## How to publish an extension?+The publishing process is still in development, but we are working on it and will update this section of the documentation as soon as it is ready.diff --git a/docs/ext-sdk-introduction.md b/docs/ext-sdk-introduction.mdnew file mode 100644index 000000000..cc4f02988--- /dev/null+++ b/docs/ext-sdk-introduction.md@@ -0,0 +1,32 @@+---+title: Getting started with the Extensions SDK+slug: /sdk-introduction+---++## What are the extensions?+Swetrix allows you to create your own extensions to extend the functionality of the platform.+These extensions work similarly to browser extensions and allow you to access and process analytics data, display customised pages and much more.++You can also publish your extensions in the Swetrix Marketplace for others to use.++:::caution+Swetrix Marketplace and the extensions SDK are still in development, the documentation may be updated frequently and some APIs may change.+:::++## How do they work?+Extensions can communicate with the Swetrix platform via the Swetrix SDK.+The Swetrix SDK is a module that gives you the ability to configure different event listeners and also to transfer data from the extension to the Swetrix dashboard.+All user-installed extensions run in parallel and are isolated from each other.++The extension itself is a JavaScript file which consists of a function that takes an sdk object as an argument.++This object consists of all the APIs you can use when writing your extension.++A simple example of an extension structure:+```javascript+(async (sdk) => {+ // Your extension code goes here..+})+```++You can find full and in-detail explained examples in our [GitHub repository](https://github.com/Swetrix/extension-examples).diff --git a/docs/ext-sdk-reference.md b/docs/ext-sdk-reference.mdnew file mode 100644index 000000000..561085fe1--- /dev/null+++ b/docs/ext-sdk-reference.md@@ -0,0 +1,86 @@+---+title: Extensions SDK reference+slug: /sdk-reference+---++## Event listeners+Event listeners allow you to listen to the specific events from the Swetrix Dashboard and run your custom code based on it.+The method `addEventListener` works by adding a function to the list of event listeners for the specified event type on which it's called.++If the function or object is already in the list of event listeners for this target, the function or object is not added a second time.++Here is a basic example of an event listener:+```javascript+(async (sdk) => {+ sdk.addEventListener('projectinfo', ({ id }) => {+ // Your code goes here..+ })+})+```++Currently, the following events are available:+1. `load` - The event is triggered when the dashboard loads a new set of analytics data. For example, when user opens dashboard for the first time, changes the data range or time bucket.+2. `timeupdate` - This event is triggered when user changes the time bucket, time perios or sets the date range.+3. `filtersupdate` - This event is triggered when user changes the filters.+4. `projectinfo` - This event is triggered on load and it supplies information about the project it's running on.++## addExportDataRow()+The `addExportDataRow` function adds a new export data row into the 'Export data' dropdown.+The function takes 2 parameters:+1. The name of the row.+2. The callback which is called when the user clicks on the row.++Here is an example of how to use this function:+```javascript+(async (sdk) => {+ sdk.addExportDataRow('As JSON', () => {+ // Your code goes here..+ })+})+```++## removeExportDataRow()+The `removeExportDataRow` function removes an export data row from the dropdown. It takes the name of the export data row as a parameter.++```javascript+sdk.removeExportDataRow('As JSON')+```++## addPanelTab()++The `addPanelTab` function allows you to add a new panel tab into the dashboard panels.++For example, Swetrix has a Country panel with 2 pre-built tabs: countries list and a map.+By using this method, you can add a custom tab with a custom HTML (or just text) content.++This function takes 3 parameters:+1. Panel ID - the ID of the panel where you want to add a new tab.+2. The content of your tab, can be either text or stringified HTML.+3. `onOpen` callback - a callback that is called when the user opens the tab.++```javascript+sdk.addPanelTab('cc', '<h2>Custom Content</h2>', () => {+ // This part is triggered when the tab is opened+ // Your code goes here..+})+```++Currently, Swetrix supports the following panels you can inject a tab into:+1. `cc` - Country+2. `pg` - Page+3. `lc` - Locale+4. `ref` - Referrer+5. `dv` - Device type+6. `br` - Browser+7. `os` - OS name+8. `so` - utm_source+9. `me` - utm_medium+10. `ca` - utm_campaign++## removePanelTab()++The `removePanelTab` function allows you to remove a panel tab from the dashboard panels. It takes the ID of the panel as a parameter.++```javascript+sdk.removePanelTab('cc')+```\ No newline at end of filediff --git a/sidebars.js b/sidebars.jsindex e3ed21da5..8c520be13 100644--- a/sidebars.js+++ b/sidebars.js@@ -1,6 +1,6 @@module.exports = {docs: {- "Get Started": [+ 'Get Started': ['introduction','add-script','script-reference',@@ -11,5 +11,10 @@ module.exports = {items: ['integrations/wordpress', 'integrations/webflow', 'integrations/wix', 'integrations/ghost', 'integrations/django', 'integrations/sveltekit'],}],+ 'Extensions SDK': [+ 'ext-sdk-introduction',+ 'ext-sdk-faq',+ 'ext-sdk-reference',+ ],},}