An analytics value can look correct and still behave incorrectly. The text “2” and the number 2 are different values. The text “false” is not the Boolean false. These differences matter when a script adds quantities or decides whether an event qualifies.
For analysts, the useful starting point is a data contract: what each field means, which type it accepts, and how missing or invalid values should be handled. Conversion comes after that decision.
Give each field a meaning and a type
Consider a hypothetical product interaction with product_id set to “0072”, quantity set to “2”, unit_price set to “19.90”, and is_member set to “false”. All four values are strings because they are quoted. Their business meanings are different. This example describes proposed input, not a tested website.
Keep product_id as text: its leading zeros may be meaningful. Quantity represents a count. Unit price represents an amount. Membership represents a yes-or-no state. Applying the same conversion to every field would destroy useful distinctions.
JavaScript values have types such as string, number, Boolean, undefined, and object. MDN’s data structures guide explains dynamic typing and conversion. A variable name does not enforce the type of the value assigned to it.
Inspect both a value and its type when investigating tracking. For example, typeof "2" returns "string", while typeof 2 returns "number". A field called quantity can still contain text, so its name is not sufficient evidence.
Convert numbers without inventing zero
"2" + 1 produces , because addition with a string can concatenate text. produces . Conversion changes the operation, but it does not establish whether the input is valid for your field.
