Skip to content

Conversation

@bokelley
Copy link
Contributor

@bokelley bokelley commented Nov 3, 2025

Problem

The targeting browser was throwing a JavaScript error when rendering audiences that don't have a type property:

TypeError: undefined is not an object (evaluating 'audience.type.replace')

Console logs showed:

  • 255 custom targeting keys loaded successfully
  • Error occurred on line 533 of targeting browser when rendering audiences
  • Some audiences from GAM don't include type, segment_type, or status fields

Solution

Added conditional rendering for audience properties that may be undefined:

Changes in templates/targeting_browser.html:

  1. Line 532-534: Only render type badge if audience.type exists
  2. Line 541: Only render segment_type badge if audience.segment_type exists
  3. Line 542: Added null check for audience.status before comparing

Before:

<span class="badge">${audience.type.replace('_', ' ')}</span>
<span class="badge">${audience.segment_type}</span>
${audience.status !== 'ACTIVE' ? ... : ''}

After:

${audience.type ? `<span class="badge">${audience.type.replace('_', ' ')}</span>` : ''}
${audience.segment_type ? `<span class="badge">${audience.segment_type}</span>` : ''}
${audience.status && audience.status !== 'ACTIVE' ? ... : ''}

Impact

  • ✅ Targeting browser now renders all audiences without JavaScript errors
  • ✅ Audiences without type/segment_type/status simply don't show those badges
  • ✅ No impact on functionality - purely defensive coding

Testing

  • Verified error was on line 533 with audience.type.replace
  • Added null checks for all audience properties that could be undefined
  • Change is template-only, no backend logic affected

Related to PR #681 which fixed similar field name mismatch in product targeting selector.

Fixes TypeError when rendering audiences with missing type/segment_type fields.

**Problem:**
- Some audiences from GAM don't have a `type` property
- JavaScript tried to call `audience.type.replace('_', ' ')` on undefined
- Caused error: "undefined is not an object (evaluating 'audience.type.replace')"
- Also `audience.segment_type` could be missing

**Solution:**
- Added conditional rendering: only show type badge if `audience.type` exists
- Added conditional rendering: only show segment_type badge if exists
- Added null check for `audience.status` to avoid similar issue

**Impact:**
- Targeting browser now renders all audiences without errors
- Audiences without type/segment_type simply don't show those badges
- No more console errors on targeting browser page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit b8e6e77 into main Nov 3, 2025
10 checks passed
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
…pe (adcontextprotocol#682)

Fixes TypeError when rendering audiences with missing type/segment_type fields.

**Problem:**
- Some audiences from GAM don't have a `type` property
- JavaScript tried to call `audience.type.replace('_', ' ')` on undefined
- Caused error: "undefined is not an object (evaluating 'audience.type.replace')"
- Also `audience.segment_type` could be missing

**Solution:**
- Added conditional rendering: only show type badge if `audience.type` exists
- Added conditional rendering: only show segment_type badge if exists
- Added null check for `audience.status` to avoid similar issue

**Impact:**
- Targeting browser now renders all audiences without errors
- Audiences without type/segment_type simply don't show those badges
- No more console errors on targeting browser page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants