{"id":22439618,"url":"https://github.com/oddcamp/analytics","last_synced_at":"2025-12-31T14:29:45.052Z","repository":{"id":62164108,"uuid":"557959954","full_name":"oddcamp/analytics","owner":"oddcamp","description":"A collection of analytics helper functions.","archived":false,"fork":false,"pushed_at":"2023-02-27T02:27:49.000Z","size":444,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-01T14:22:07.393Z","etag":null,"topics":["analytics","google-analytics","tracker","tracking"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oddcamp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-26T16:16:50.000Z","updated_at":"2022-10-31T21:48:28.000Z","dependencies_parsed_at":"2023-02-13T10:31:14.360Z","dependency_job_id":null,"html_url":"https://github.com/oddcamp/analytics","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oddcamp%2Fanalytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oddcamp%2Fanalytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oddcamp%2Fanalytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oddcamp%2Fanalytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oddcamp","download_url":"https://codeload.github.com/oddcamp/analytics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245816081,"owners_count":20677025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","google-analytics","tracker","tracking"],"created_at":"2024-12-06T01:15:28.540Z","updated_at":"2025-12-31T14:29:45.019Z","avatar_url":"https://github.com/oddcamp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Odd Camp analytics helpers library\n\nA collection of analytics helper functions.\n\n## Supported analytics services\n\n- Plausible\n- Ahoy\n\n### Plausible\n\nMake sure the API object is available at `window.plausible`. It usually is if the snippet was inserted via `\u003cscript\u003e`.\n\n### Ahoy\n\nMake sure the API object is available at `window.ahoy`. If you use it as NPM module you can expose the object like this:\n\n```js\nimport ahoy from \"ahoy.js\"\n\nwindow.ahoy = ahoy\n```\n  \n\n###\n\n## Usage\n\n1. Install\n\n```js\n$ yarn add @oddcamp/analytics\n```\n\n2. Enjoy\n\n```js\nimport { enableAutoEventAnalytics } from \"@oddcamp/analytics\"\n\nenableAutoEventAnalytics()\n```\n\nHTML\n\n```html\n  \u003ca href=\"/\" data-event-analytics='{\"name\": \"Click\", \"props\": {\"trigger\": \"anchor\"}}'\u003e\n    Link\n  \u003c/a\u003e\n```\n\nERB\n\n```erb\n  \u003c%= link_to 'Link', root_path, data: {event_analytics: {name: 'Click', props: {trigger: 'anchor'}}} %\u003e\n```\n\nJSX\n\n```jsx\n  \u003ca href=\"/\" data-event-analytics={JSON.stringify({name: 'Click', props: {trigger: 'anchor'}})}\u003e\n    Link\n  \u003c/a\u003e\n```\n\n## Development\n\n1. Create `.env` and set variables of analytics services you prefer to test:\n    - `PLAUSIBLE_DOMAIN=something.site`\n    - `AHOY_SCRIPT_URL=https://unpkg.com/ahoy.js@0.4.0/dist/ahoy.js`\n2. `$ yarn install`\n3. `$ yarn dev`\n3. [localhost:1234](http://localhost:1234)\n\n## API\n\n### `enableAutoEventAnalytics`\n\nEnable automatic event analytics for element clicks and form submissions.\n\n_Defaults:_\n\n```js\nenableAutoEventAnalytics({\n  attributeName = `event-analytics`,\n  sourceNode = document,\n  services = [`plausible`, `ahoy`],\n  debug = false,\n})\n```\n\n_Returns:_ function which disables automatic event analytics if executed, e.g.:\n\n```js\nconst disableAutoEventAnalytics = enableAutoEventAnalytics()\n// ...\ndisableAutoEventAnalytics()\n```\n\nThe value of `attributeName` attribute must be a JSON, e.g.:\n\n```js\n{\n  \"name\": \"\", // name; mandatory\n  \"props\": {}, // custom properties\n  \"options\": {\n    \"allFieldsAsProps\": false, // sets all form fields as props on form submissions\n  }\n}\n```\n\nGet all form field name and value pairs as props using boolean `allFieldsAsProps`\noption or specify field(s) manually by setting `data-event-analytics-field`\nattribute, e.g.\n\n```html\n  \u003cform data-event-analytics=\"{...}\"\u003e\n    \u003cinput type=\"search\" name=\"query\" data-event-analytics-field\u003e\n  \u003c/form\u003e\n```\n\nNote: the attribute name may differ if you did set a custom value for\n`attributeName` parameter (`${attributeName}-field`).\n\n### `analyticizeEvent`\n\nAnalyticizes an event.\n\n_Defaults:_\n\n```js\nanalyticizeEvent({ \n  data, \n  services = [`plausible`, `ahoy`],\n  debug = false \n})\n```\n\n_Example:_\n\n```js\nanalyticizeEvent({\n  data: {\n    name: `Event name`,\n    props: {\n      key: `value`,\n    },\n  },\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foddcamp%2Fanalytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foddcamp%2Fanalytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foddcamp%2Fanalytics/lists"}