diff --git a/README.md b/README.md index f4b447c..537c0d3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,24 @@ A collection of analytics helper functions. ## Supported analytics services - Plausible +- Ahoy + +### Plausible + +Make sure the API object is available at `window.plausible`. It usually is if the snippet was inserted via ` + + + + diff --git a/package.json b/package.json index b0977c6..bea7542 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@oddcamp/analytics", "description": "Odd Camp analytics helpers library", - "version": "0.0.6", + "version": "0.0.7", "author": "Odd Camp ", "license": "MIT", "main": "src/index.js", diff --git a/posthtml.config.js b/posthtml.config.js index 6c137de..96e0fe2 100644 --- a/posthtml.config.js +++ b/posthtml.config.js @@ -3,7 +3,10 @@ require(`dotenv`).config({ path: `.env` }) module.exports = { plugins: { "posthtml-expressions": { - locals: { plausible_domain: process.env.PLAUSIBLE_DOMAIN }, + locals: { + plausible_domain: process.env.PLAUSIBLE_DOMAIN, + ahoy_script_url: process.env.AHOY_SCRIPT_URL, + }, }, }, } diff --git a/src/index.js b/src/index.js index 54ce138..df719a6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ import { isPlainObject, get } from "lodash" -const SERVICES = [`plausible`] +const SERVICES = [`plausible`, `ahoy`] function enableAutoEventAnalytics({ attributeName = `event-analytics`, @@ -196,6 +196,22 @@ function analyticizeEvent({ data, services = SERVICES, debug = false } = {}) { } break } + + case `ahoy`: { + if (window && window.ahoy) { + debugLog(debug, `Ahoy event analyzation has been requested`, data) + + window.ahoy.track(data.name, { ...(data.props || {}) }) + + debugLog(debug, `Ahoy event has been analyzed`, data) + } else { + debugLog( + debug, + `Ahoy event analysation requested, but service is not available` + ) + } + break + } } }) } @@ -206,6 +222,10 @@ function anyServicesAvailable(services) { case `plausible`: { return !!window.plausible } + + case `ahoy`: { + return !!window.ahoy + } } return false