less than a minute read • Updated 8 days ago
Pass session variables through the cart
How to store custom data in the Foxy cart session and access it in the transaction datafeed.
Session variables let you store custom data in a customer’s cart session that is not tied to any specific product — commonly used for analytics tracking, affiliate attribution, or syncing a customer ID with your own system. This data is available in the cart JSON and is included in the transaction datafeed when an order is completed.
How to set it up
Add any parameter prefixed with h: to a cart link or form:
https://YOURSTORE.foxycart.com/cart?name=Product+Name&price=10.00&h:customer_id=12345
Multiple session variables can be added in the same request:
https://YOURSTORE.foxycart.com/cart?name=Product+Name&price=10.00&h:customer_id=12345&h:affiliate_id=ABC
The same works in a form:
<form action="https://YOURSTORE.foxycart.com/cart" method="post">
<input type="hidden" name="name" value="Product Name" />
<input type="hidden" name="price" value="10.00" />
<input type="hidden" name="h:customer_id" value="12345" />
<input type="submit" value="Buy Now" />
</form>
Accessing session variables in JavaScript
Session variables are available in FC.json.custom_fields:
FC.client.on('ready.done', function() {
console.log(FC.json.custom_fields.customer_id);
});
custom_fields sits at the top level of the cart JSON — it is not nested under individual items, even if the h: parameter was added alongside a specific product.
Accessing session variables in Twig
Session variables are also available as custom_fields in Twig, for use in templates like the web receipt or email receipt:
{{ custom_fields.customer_id.value }}
Adding session variables without adding a product
Use cart=view to add session variables to the cart without adding a product:
FC.client.on('ready.done', function() {
FC.client.request('https://' + FC.settings.storedomain + '/cart?h:foo=bar');
});
Notes
Session variables are not tied to products — they persist for the life of the session regardless of what products are in the cart.
Session variables are never displayed to the customer, at any point in the cart, checkout, or receipt.
Maximum value length is 700 characters.
Do not sign
h:values if using link and form validation.After a transaction is completed, session variables are accessible via the transaction XML datafeed or the API.
This is different from the session cookie itself (
fcsid) — see Configure the session domain and cookie path if you need to control where that cookie is set, or JavaScript events reference for the full list of events available onFC.client.