Geofence
Draw a zone, drag a pin
Draw a zone, drag a pin. Enter, exit, and dwell change the offer in this tab. A geofence in an app is the same test, usually run on a phone instead of a pin.
Understanding the labHow to use it and why you'd want to
Why you'd want to
A ring and a draggable pin show enter, exit, and dwell, written only in this tab. Nothing is posted, and the lab does not queue an event of its own.
How to use it
- Drag the pin and watch the ring test.
- Enter, exit, and dwell are written in this tab.
- The test does not call the network.
The sample zone is centered on the coarse place from this request: Columbus, OH, US. Drag the pin. Nothing leaves this browser.
Triggered content
Outside the zone
Default page. The local offer is off.
Draw
Click the map to add corners, then close the zone. Or load the sample again.
Outside
Events
Drag the pin into the zone. Enter fires at the edge. Dwell fires after eight seconds.
How it works
- A zone is a ring of points. Closing the ring makes it a fence.
- The test pin is draggable. Each move checks whether the pin is inside the ring.
- Crossing the edge writes enter or exit. Staying inside for eight seconds writes dwell.
- The card is the triggered content: default, local offer, then a dwell offer.
- The zone, the pin, and the log stay in this browser. Nothing is sent.
Inside the ring
A ray cast. No library, and no network.
function insideZone(point, ring) {
let inside = false
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
const a = ring[i]
const b = ring[j]
const crosses = a.lat > point.lat !== b.lat > point.lat
if (!crosses) continue
const x = ((b.lng - a.lng) * (point.lat - a.lat)) / (b.lat - a.lat) + a.lng
if (point.lng < x) inside = !inside
}
return inside
}
// Enter, exit, and an 8 second dwell stay in this tab.
if (inside && !wasInside) log("enter")
if (!inside && wasInside) log("exit")
if (inside && stayedMs >= 8000) log("dwell")WalkthroughHow we built itShowHide
Example vendor setup is marked below. eVar and event numbers are examples. This lab does not call Adobe.
The geofence lab draws a ring, tests a draggable pin, and writes enter, exit, and dwell in this tab without posting anything or queueing its own event. The lab does not call Adobe.
Build a ring
ringAround walks bearings around a center and calls destination for a distance in miles. The sample ring uses eight sides and two miles. The center is the coarse request place, or Chicago when that place has no point.
Test the pin with a ray cast
pointInPolygon returns false for a ring with fewer than three points. Otherwise it counts edge crossings and flips inside. The pin starts east of the center, outside the two-mile sample.
Write enter, exit, and dwell locally
When the closed ring’s inside flag changes, the effect prepends enter or exit and keeps twelve rows. Enter starts an eight-second timer. If the pin is still that entry, it prepends dwell. The log is component state.
Leave the network alone
The widget is marked data-track-ignore. The page says the zone, the pin, and the log stay in this browser. This component does not call trackLabEvent.
From the code
Inside is a ray cast. A short ring is outside.
/** Ray cast. A ring with fewer than three points is outside. */
export function pointInPolygon(point: LatLng, ring: LatLng[]) {
if (ring.length < 3) return false
let inside = false
for (let index = 0, previous = ring.length - 1; index < ring.length; previous = index, index += 1) {
const yi = ring[index].latitude
const xi = ring[index].longitude
const yj = ring[previous].latitude
const xj = ring[previous].longitude
const crosses = yi > point.latitude !== yj > point.latitude
if (!crosses) continue
const x = ((xj - xi) * (point.latitude - yi)) / (yj - yi) + xi
if (point.longitude < x) inside = !inside
}
return inside
}A crossing writes enter or exit. Eight seconds inside writes dwell.
useEffect(() => {
if (!closed) return
if (wasInside.current === inside) return
wasInside.current = inside
entry.current += 1
const token = entry.current
setDwell(false)
const kind: FenceEvent["kind"] = inside ? "enter" : "exit"
setEvents((current) => [{ id: crypto.randomUUID(), kind, at: new Date().toISOString() }, ...current].slice(0, 12))
if (!inside) return
const timer = window.setTimeout(() => {
if (token !== entry.current) return
setDwell(true)
const dwellKind: FenceEvent["kind"] = "dwell"
setEvents((current) => [{ id: crypto.randomUUID(), kind: dwellKind, at: new Date().toISOString() }, ...current].slice(0, 12))
}, 8000)
return () => window.clearTimeout(timer)Google and Adobe
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: "fence_enter_example",
kind: "enter",
})Example implementation. This site does not call Adobe. eVar75, prop75, and event75 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 eVar75 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: {
fenceKind: "enter",
},
},
})Example hit. eVar75 is hit-scoped in this example. prop75 dies at the same hit.
s.eVar75 = "enter"
s.prop75 = "enter"
s.events = "event75"
s.linkTrackVars = "eVar75,prop75,events"
s.linkTrackEvents = "event75"
s.tl(true, "o", "fence_enter_example")Translation
Each lab field, the GA4 name, and the example Adobe variable. Scope is the part that usually gets lost in the translation.
Kind
GA4. Not sent. fence_enter_example is a fake name. enter, exit, and dwell are rows in this tab.
Adobe. Example eVar75, expire on the hit. Not sent.
Scope. A local log for this hit. It is not a user property and it is not a visit event.
Inside
GA4. Not sent. pointInPolygon’s boolean stays in the widget.
Adobe. Example prop75. Not sent.
Scope. A view state on the hit. It is not a user property and it ends with the tab, not a stored visit. It is an event on the hit, not a user property, and it does not last for the visit.
Ring
GA4. Not sent.
Adobe. Example eVar75. Not sent.
Scope. Points in component state. They are not an event, not a user property, and not a hit or visit field.
Dwell offer
GA4. Not sent. The card copy changes after eight seconds.
Adobe. Example prop75. Not sent.
Scope. Shown on the hit. It is not a user property and it is not kept for the visit. It is an event on the hit, not a user property, and it does not last for the visit.
Recommended next
Why these picksReading path transitions…