Skip to content

Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.

fix(hotjar): align survey export with the public v1 API

Rudy Celekli58e215f57bf9
diff --git a/tests/clis/hotjar-surveys.test.cjs b/tests/clis/hotjar-surveys.test.cjs
new file mode 100644
index 0000000..7fd2e3d
--- /dev/null
+++ b/tests/clis/hotjar-surveys.test.cjs
@@ -0,0 +1,15 @@
+const { test } = require('node:test')
+const assert = require('node:assert/strict')
+const { spawnSync } = require('node:child_process')
+const path = require('node:path')
+const cli = path.resolve(__dirname, '../../tools/clis/hotjar.js')
+function run(args, oracle = "throw new Error('unexpected fetch')") {
+ const code = `let calls=0; global.fetch=async (url,options)=>{ const assert=require('node:assert/strict');if(${JSON.stringify(args.includes('--dry-run'))})throw new Error('unexpected preview fetch');const u=new URL(url);calls++;if(calls===1){assert.equal(u.href,'https://api.hotjar.io/v1/oauth/token');assert.equal(options.method,'POST');assert.equal(options.headers['Content-Type'],'application/x-www-form-urlencoded');const form=new URLSearchParams(options.body);assert.equal(form.get('grant_type'),'client_credentials');assert.equal(form.get('client_id'),'fixture+/id');assert.equal(form.get('client_secret'),'fixture+/secret');return new Response(JSON.stringify({access_token:'fixture-token'}));}assert.equal(calls,2);assert.equal(options.headers.Authorization,'Bearer fixture-token');${oracle};return new Response(JSON.stringify({accepted:true}));};process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)});`
+ const r=spawnSync(process.execPath,['-e',code],{encoding:'utf8',timeout:10000,env:{...process.env,HOTJAR_CLIENT_ID:'fixture+/id',HOTJAR_CLIENT_SECRET:'fixture+/secret'}})
+ assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)
+}
+test('survey list authenticates on v1 and forwards the cursor and page size',()=>assert.equal(run(['surveys','list','--site-id','42','--limit','25','--cursor','cursor+/='],"assert.equal(u.pathname,'/v1/sites/42/surveys');assert.equal(u.searchParams.get('limit'),'25');assert.equal(u.searchParams.get('cursor'),'cursor+/=');").accepted,true))
+test('survey first page retains default page size without a cursor',()=>assert.equal(run(['surveys','list','--site-id','42'],"assert.equal(u.pathname,'/v1/sites/42/surveys');assert.equal(u.searchParams.get('limit'),'100');assert.equal(u.searchParams.has('cursor'),false);").accepted,true))
+test('survey responses authenticate on v1 and preserve cursor',()=>assert.equal(run(['surveys','responses','--site-id','42','--survey-id','s1','--cursor','cursor+/='],"assert.equal(u.pathname,'/v1/sites/42/surveys/s1/responses');assert.equal(u.searchParams.get('cursor'),'cursor+/=');").accepted,true))
+test('survey preview stays offline and masks authorization',()=>{const p=run(['surveys','list','--site-id','42','--cursor','next','--dry-run']);const u=new URL(p.url);assert.equal(u.pathname,'/v1/sites/42/surveys');assert.equal(u.searchParams.get('cursor'),'next');assert.equal(p.headers.Authorization,'***')})
+test('missing survey ID never authenticates',()=>assert.match(run(['surveys','responses','--site-id','42']).error,/survey-id/))
diff --git a/tools/clis/hotjar.js b/tools/clis/hotjar.js
index 0b2e386..cbf30ab 100755
--- a/tools/clis/hotjar.js
+++ b/tools/clis/hotjar.js
@@ -3,8 +3,8 @@
const rawArgs = process.argv.slice(2)
const CLIENT_ID = process.env.HOTJAR_CLIENT_ID
const CLIENT_SECRET = process.env.HOTJAR_CLIENT_SECRET
-const OAUTH_URL = 'https://api.hotjar.io'
-const BASE_URL = 'https://api.hotjar.io/v2'
+const OAUTH_URL = 'https://api.hotjar.io/v1'
+const BASE_URL = 'https://api.hotjar.io/v1'
if ((!CLIENT_ID || !CLIENT_SECRET) && rawArgs.length > 0) {
console.error(JSON.stringify({ error: 'HOTJAR_CLIENT_ID and HOTJAR_CLIENT_SECRET environment variables required' }))
@@ -92,9 +92,12 @@ async function main() {
case 'surveys':
if (!siteId) { result = { error: '--site-id required' }; break }
switch (sub) {
- case 'list':
- result = await api('GET', `/sites/${siteId}/surveys`)
+ case 'list': {
+ const params = new URLSearchParams({ limit })
+ if (cursor) params.set('cursor', cursor)
+ result = await api('GET', `/sites/${siteId}/surveys?${params}`)
break
+ }
case 'responses': {
const surveyId = args['survey-id']
if (!surveyId) { result = { error: '--survey-id required' }; break }
diff --git a/tools/integrations/hotjar.md b/tools/integrations/hotjar.md
index 42c1e2c..d76e1e6 100644
--- a/tools/integrations/hotjar.md
+++ b/tools/integrations/hotjar.md
@@ -6,7 +6,7 @@ Behavior analytics platform with heatmaps, session recordings, and surveys for u
| Integration | Available | Notes |
|-------------|-----------|-------|
-| API | ✓ | Surveys, Responses, Sites, Heatmaps, Recordings |
+| API | ✓ | Survey export and user lookup (Scale plans) |
| MCP | - | Not available |
| CLI | ✓ | [hotjar.js](../clis/hotjar.js) |
| SDK | ✓ | JavaScript tracking snippet, Identify API, Events API |
@@ -40,14 +40,6 @@ grant_type=client_credentials&client_id={client_id}&client_secret={client_secret
## Common Agent Operations
-### List Sites
-
-```bash
-GET https://api.hotjar.io/v1/sites
-
-Authorization: Bearer {access_token}
-```
-
### List Surveys
```bash
@@ -66,29 +58,23 @@ Authorization: Bearer {access_token}
Supports cursor-based pagination with `cursor` and `limit` parameters.
-### List Heatmaps
-
-```bash
-GET https://api.hotjar.io/v1/sites/{site_id}/heatmaps
-
-Authorization: Bearer {access_token}
-```
+The public API reference documents survey export and user lookup. It does not
+provide the site-list, heatmap, recording, or form-export routes shown in the
+legacy CLI commands. Those commands are not verified public API integrations;
+use the dashboard for those workflows. Find site IDs in Sites & Organizations.
-### List Recordings
+Survey export requires Ask Scale. API credentials expire after one year and
+must be replaced. The documented public API version is `v1`.
```bash
-GET https://api.hotjar.io/v1/sites/{site_id}/recordings
-
-Authorization: Bearer {access_token}
+node tools/clis/hotjar.js surveys list --site-id 42 --limit 25 --cursor '<next_cursor>'
+node tools/clis/hotjar.js surveys responses --site-id 42 --survey-id '<survey_id>' --cursor '<next_cursor>'
```
-### List Forms
-
-```bash
-GET https://api.hotjar.io/v1/sites/{site_id}/forms
+Repeat the original command with the returned `next_cursor` to retrieve another
+page. Request previews use the same URL and remain offline.
-Authorization: Bearer {access_token}
-```
+Source: [Hotjar API Reference](https://help.hotjar.com/hc/en-us/articles/36820005914001-Hotjar-API-Reference).
## Key Metrics
@@ -98,30 +84,12 @@ Authorization: Bearer {access_token}
- `created_at` - Response timestamp
- `device_type` - Desktop, mobile, tablet
-### Heatmap Data
-- `url` - Page URL
-- `click_count` - Total clicks tracked
-- `visitors` - Unique visitors
-- `created_at` - Heatmap creation date
-
-### Recording Data
-- `recording_id` - Unique recording ID
-- `duration` - Session duration
-- `pages_visited` - Pages in session
-- `device` - Device information
-
## Parameters
-### Survey Responses
-- `limit` - Results per page (default: 100)
-- `cursor` - Pagination cursor from previous response
-- `sort` - Sort order (default: created_at desc)
-
-### Recordings
-- `limit` - Results per page
-- `cursor` - Pagination cursor
-- `date_from` - Start date filter
-- `date_to` - End date filter
+### Surveys and Survey Responses
+- `limit` - Results per page (CLI default: 100; API maximum: 100)
+- `cursor` - The `next_cursor` returned by the previous page
+- Responses are sorted by creation date descending; filtering by date is not supported.
## When to Use