Skip to content

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

fix(segment): reject non-object event properties and traits

Rudy Celeklia8b89dcf2014
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json
index 39ddc4c..68a230d 100644
--- a/.claude-plugin/marketplace.json
+++ b/.claude-plugin/marketplace.json
@@ -6,7 +6,7 @@
},
"metadata": {
"description": "Marketing skills for AI agents — conversion optimization, copywriting, SEO, paid ads, and growth",
- "version": "2.11.26",
+ "version": "2.11.27",
"repository": "https://github.com/coreyhaines31/marketingskills"
},
"plugins": [
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json
index f1a5cf8..aabe26f 100644
--- a/.claude-plugin/plugin.json
+++ b/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "marketing-skills",
"description": "Marketing skills for AI agents — conversion optimization, copywriting, SEO, paid ads, ad creative, and growth",
- "version": "2.11.26",
+ "version": "2.11.27",
"author": {
"name": "Corey Haines"
},
diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json
index 45d9d89..9cd1f4c 100644
--- a/.codex-plugin/plugin.json
+++ b/.codex-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "marketing-skills",
"description": "Marketing skills for AI agents — conversion optimization, copywriting, SEO, paid ads, ad creative, and growth",
- "version": "2.11.26",
+ "version": "2.11.27",
"author": {
"name": "Corey Haines"
},
diff --git a/VERSIONS.md b/VERSIONS.md
index dc6d5ce..4f07be1 100644
--- a/VERSIONS.md
+++ b/VERSIONS.md
@@ -57,6 +57,10 @@ Current versions of all skills. Agents can compare against local versions to che
## Recent Changes
+### 2.11.27 (2026-10-10)
+
+- Validate Segment event properties and identity traits as dictionaries before sending.
+
### 2.11.26 (2026-10-08)
- **lead-magnets** (2.0.0 → 2.1.0): new `references/content-to-skill.md` (plus corpus design and release companions) on packaging a course, webinar series, podcast, or newsletter archive you own as an installable agent skill: a new kind of lead magnet. From @rudycelekli's #725 (closes #432), folded in rather than added as a new skill. Triggers added: 'course as a skill,' 'package our content as an agent skill.' **ai-seo** (2.7.5 → 2.7.6) points to it.
diff --git a/tests/clis/segment-json-objects.test.cjs b/tests/clis/segment-json-objects.test.cjs
new file mode 100644
index 0000000..f4cc1c5
--- /dev/null
+++ b/tests/clis/segment-json-objects.test.cjs
@@ -0,0 +1,30 @@
+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/segment.js')
+function run(command, flag, value, preview = false) {
+ const args = [...command, '--user-id', 'fixture-user', flag, value]
+ if (preview) args.push('--dry-run')
+ const source = `global.fetch = async (url, opts) => { process.stderr.write('FETCH_CALLED'); return { status: 200, text: async () => JSON.stringify({ body: JSON.parse(opts.body) }) }; }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`
+ return spawnSync(process.execPath, ['-e', source], {encoding: 'utf8', env: { ...process.env, SEGMENT_WRITE_KEY: 'fixture' }, timeout: 5000})
+}
+const commands = [ [['track', 'event', '--event', 'Purchased'], '--properties'], [['page', 'view'], '--properties'], [['identify', 'user'], '--traits'] ]
+test('event object containers fail before delivery or preview', () => {
+ for (const [command, flag] of commands) for (const value of ['null', '[]', 'true', '42', '"text"']) {
+ for (const preview of [false, true]) {
+ const result = run(command, flag, value, preview)
+ assert.equal(result.status, 1, `${command}: ${value}: ${result.stdout}`)
+ assert.equal(result.stderr.includes('FETCH_CALLED'), false)
+ assert.match(JSON.parse(result.stderr).error, /must be a JSON object/)
+ assert.equal(result.stdout, '')
+ }
+ }
+})
+test('nested event objects and empty dictionaries survive delivery', () => {
+ for (const [command, flag] of commands) for (const data of [{}, {customer: {name: 'Zoë'}, items: [1, 2], active: false}]) {
+ const result = run(command, flag, JSON.stringify(data))
+ assert.equal(result.status, 0, result.stderr)
+ assert.deepEqual(JSON.parse(result.stdout).body[flag.slice(2)], data)
+ }
+})
diff --git a/tools/clis/segment.js b/tools/clis/segment.js
index d231d12..924adc5 100755
--- a/tools/clis/segment.js
+++ b/tools/clis/segment.js
@@ -109,6 +109,13 @@ function withDeliveryMetadata(body) {
return body
}
+function requireObject(value, name) {
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
+ throw new Error(`--${name} must be a JSON object`)
+ }
+ return value
+}
+
async function main() {
let result
@@ -123,6 +130,7 @@ async function main() {
}
if (args.properties) {
try { body.properties = JSON.parse(args.properties) } catch { result = { error: 'Invalid JSON in --properties' }; break }
+ requireObject(body.properties, 'properties')
}
result = await trackApi('POST', '/track', withDeliveryMetadata(body))
break
@@ -138,6 +146,7 @@ async function main() {
const body = eventIdentity()
if (args.traits) {
try { body.traits = JSON.parse(args.traits) } catch { result = { error: 'Invalid JSON in --traits' }; break }
+ requireObject(body.traits, 'traits')
}
result = await trackApi('POST', '/identify', withDeliveryMetadata(body))
break
@@ -154,6 +163,7 @@ async function main() {
if (args.name) body.name = args.name
if (args.properties) {
try { body.properties = JSON.parse(args.properties) } catch { result = { error: 'Invalid JSON in --properties' }; break }
+ requireObject(body.properties, 'properties')
}
result = await trackApi('POST', '/page', withDeliveryMetadata(body))
break