For a refresher on what cookies Heap sets and why, see What cookies does Heap set and what are they used for?
Before we get into best practices to limit cookie size, some important notes on how Heap generates cookies, and under what circumstances cookie bloat can occur.
In Heap, cookies are generated per-environment or per-parent domain. Each Heap environment that is loaded will yield 3 cookies.
Cookies are stored indefinitely until they are cleared, which happens either when the user clears their cookies, or when Heap’s clearEventProperties API is called. If the user doesn’t clear cookies and no other action is taken, those properties will still be attached to all of the user’s new events over a year later, which creates bloat.
If you use multiple, separate projects and environments, with an overlap of users who visit the same environments and projects within the same browser session, you may encounter issues with your cookie size limit. If the sum of all cookies for your parent exceeds 8kb, this may result in a failure of the page to load.
Cookie bloat can also happen when a Heap user is conducting testing across multiple Heap installations.
Heap is just one of many applications that may be contributing to the overall 8kb limit. It’s worth evaluating all applications which load cookies on your site when investigating this issue.
Solutions
We have several recommendations for limiting cookie size on your Heap account.
Reduce the number of properties sent via the addEventProperties() API. When doing so, be as selective as possible about which properties to send. Depending on your use case, reducing bloat from addEventProperties is the “lowest hanging fruit” solution to reduce your overall cookie size.
Always call clearEventProperties() ahead of addEventProperties(). This way, only the “right” properties are added to hp2-props cookies
(where event properties are stored) and other historical properties that are still in the cookie but not actually relevant to the page or user flow are cleared.
Use alternative types of properties, such as:
- Snapshots
- User properties (particularly for properties that won’t change across the user journey)
- Conditional properties (so event properties are only sent on Production environments)
Consolidate your Heap installations under one single environment instead of in multiple environments.