Last updated
This browser
Start camera asks for video only, and prefers the rear camera when the phone has one. Stop, hiding the page, or leaving it turns the camera off. No microphone is requested.
Decoding stays in this browser. Frames, photos, and the text of a code are not uploaded, stored, or sent to a scanning service. A code is shown as text. This page does not open it.
Why you'd want to
Camera frames are drawn to a canvas and read with BarcodeDetector, or with jsqr when that API is missing. The text stays on the page, and a code is not opened or uploaded.
How to use it
Camera off. Permission has not been requested.
Decoded text
Nothing decoded yet.
Shown as text only. This page does not open a link, run the contents, or follow instructions inside a code.
Example vendor setup is marked below. eVar and event numbers are examples. This lab does not call Adobe.
The QR lab draws camera frames to a canvas and reads a code with BarcodeDetector, or with jsqr when that API is missing. The text stays on the page, and the lab does not call Adobe.
Prefer the browser detector
decodeCanvas uses BarcodeDetector with format qr_code when that constructor exists. A failure falls through.
Decode the pixels locally
The fallback reads the canvas image data and calls jsqr with inversionAttempts dontInvert. The returned text is component state.
Scan while the camera is on
scanFrame copies the video frame onto the canvas and asks decodeCanvas. It schedules another frame only while the phase is still camera.
Stop on a denied camera
phaseForMediaError maps NotAllowedError and SecurityError to denied, and every other name to unavailable. Hiding the tab stops the tracks. The lab does not call trackLabEvent.
BarcodeDetector runs first. jsqr reads the canvas pixels when that API is missing or throws.
async function decodeCanvas(canvas: HTMLCanvasElement): Promise<string | null> {
const Detector = (window as Window & { BarcodeDetector?: new (options: { formats: string[] }) => { detect: (source: CanvasImageSource) => Promise<{ rawValue?: string }[]> } }).BarcodeDetector
if (typeof Detector === "function") {
try {
const codes = await new Detector({ formats: ["qr_code"] }).detect(canvas)
const value = codes[0]?.rawValue
if (value) return value
} catch {
// Fall through to the local decoder.
}
}
const ctx = canvas.getContext("2d", { willReadFrequently: true })
if (!ctx || canvas.width === 0) return null
const image = ctx.getImageData(0, 0, canvas.width, canvas.height)
const loaded = await import("jsqr")
const jsQR = (loaded.default ?? loaded) as QrDecoder
return jsQR(image.data, image.width, image.height, { inversionAttempts: "dontInvert" })?.data ?? nullEach camera frame is drawn and decoded. The loop stops when the phase is no longer camera.
async function scanFrame() {
if (phaseRef.current !== "camera") return
const video = videoRef.current
const canvas = canvasRef.current
if (video && canvas && video.readyState >= 2 && video.videoWidth > 0) {
canvas.width = video.videoWidth
canvas.height = video.videoHeight
const ctx = canvas.getContext("2d", { willReadFrequently: true })
ctx?.drawImage(video, 0, 0)
const text = await decodeCanvas(canvas)
if (text && phaseRef.current === "camera") setResult(text)
}
if (phaseRef.current === "camera") frameRef.current = requestAnimationFrame(() => void scanFrame())This lab does not queue its own event. The Google block shows an example of how you would track the interaction. Adobe is an example too.
This lab does not queue an analytics event of its own. After Accept, the site still queues virtual_page_view for the page, with page_path and page_title. Clicks inside a data-track-ignore region are not recorded. The push below is an example, not a call this page makes. This site does not call gtag('set') or Adobe.
Example only. This page does not push this object.
// Example only. This lab does not queue this event.
dataLayer.push({
event: "qr_decode_example",
decoded: false,
})Example implementation. This site does not call Adobe. eVar95, prop95, and event95 are example variable numbers. In Launch, a data element reads the value and a rule sends it when the value changes. In the report suite, enable eVar95 with Most Recent allocation and expire it on the hit. A processing rule is unnecessary if the data element maps straight to that eVar.
Example alloy payload. _example is a placeholder schema, not a real tenant.
alloy("sendEvent", {
xdm: {
eventType: "web.webinteraction.linkClicks",
_example: {
qrText: "hello",
},
},
})Example hit. eVar95 is hit-scoped in this example. prop95 dies at the same hit.
s.eVar95 = "hello"
s.prop95 = "hello"
s.events = "event95"
s.linkTrackVars = "eVar95,prop95,events"
s.linkTrackEvents = "event95"
s.tl(true, "o", "qr_decode_example")Each lab field, the GA4 name, and the example Adobe variable. Scope is the part that usually gets lost in the translation.
Decoded text
GA4. Not sent. The text stays in component state.
Adobe. Example: do not copy the code text into eVar95.
Scope. Not a hit and not a user property.
Camera phase
GA4. Not sent. idle, camera, denied, and unavailable are page states.
Adobe. Example prop95, which dies at the hit.
Scope. Hit, if you tracked the phase. It is not a visit trait.
Decoder
GA4. Not sent. The page uses BarcodeDetector or jsqr.
Adobe. Example eVar95, expire on the hit, if you recorded which decoder ran.
Scope. Event. The decoder is a detail of one scan.
Demo code
GA4. Not sent. The sample image is a local file.
Adobe. Example event95 if you counted a demo decode. Do not store the sample text in eVar95.
Scope. Event. The sample says hello and is not a link.
Set the network's city beside a browser point you choose to share. The map draws the gap and the distance. The point stays in this tab and is not stored.
Draw a zone on the map and drag a test pin through it. Enter, exit, and dwell events change the content in this browser only. Nothing is sent or stored.
The signals used to measure a visit can also change the page.