Lesson 2 of 8
Values, Variables & Types
Everything you manipulate is a value with a type. The handful that matter for tagging: string (text), number, boolean (true/false), null/undefined (missing), plus arrays and objects (next lesson).
const name = "Aurora Headphones"; // string const price = 129; // number const onSale = true; // boolean let coupon; // undefined (not set yet)
The type trap that breaks tracking
A price scraped from the page is a string ("129"), but GA4 wants a number (129). Send the string and your revenue reports go weird. Convert explicitly:
Number("129") // 129 ✅
parseFloat("129.00") // 129
"129" * 1 // 129 (coercion)
"$1,299".replace(/[^0-9.]/g, "") // "1299" → then Number(...)const vs let
Use const by default (a value that won't be reassigned) and let only when you must change it. Avoid var, it is the old way and has surprising scope rules.
Key takeaway
Know your types, and convert strings to numbers before sending money to GA4. Default to const, reach for let when you reassign.