Skip to content

Selective Tracking

When you have multiple targets loaded but only want to detect some of them at a given time, use setActiveTargets().

All targets remain loaded in memory, but only the active ones are detected. This is useful for guided experiences, multi-step flows, or performance optimization.

Usage

javascript
// Load all targets
await tracker.addTarget('marker1', img1)
await tracker.addTarget('marker2', img2)
await tracker.addTarget('marker3', img3)

// Start (all targets active by default)
await tracker.start()

// Activate only marker2
tracker.setActiveTargets(['marker2'])

// Switch to another target
tracker.setActiveTargets(['marker1'])

// Activate several at once
tracker.setActiveTargets(['marker1', 'marker3'])

Behavior

  • If a target is being tracked and is not in the new active list, it is lost immediately (emits lost event)
  • The target remains loaded in memory and can be reactivated without reloading the image
  • By default, all targets are active after start()
MethodDescription
setActiveTargets(ids)Sets which targets are active
isTracking(id)Checks if a specific target is being tracked
getTrackedTargets()List of IDs of currently tracked targets

Example: guided experience

javascript
// Step 1: only detect the first marker
tracker.setActiveTargets(['intro'])

tracker.on('found', (id) => {
  if (id === 'intro') {
    // When the user sees the intro, activate the next one
    tracker.setActiveTargets(['step2'])
  }
})