The Challenge of Privacy-First Analytics
Running a static Nuxt site, particularly one paired with a headless CMS like Storyblok, offers significant advantages in terms of performance, security, and user privacy. The author of this approach manages a site that operates entirely without cookies and server-side tracking of individual visitors. This means no intrusive consent banners and no storage of personal browsing data. While this adheres to stringent privacy standards, it creates a critical blind spot for any business owner or freelancer: understanding the origin of leads.
The fundamental question for any lead-generating entity is simple: where do my customers come from? Is it a search engine query, a referral from a partner site, or a specific marketing campaign? Standard cookieless analytics tools, such as PostHog in its in-memory mode or Umami, can provide valuable aggregate data on referrers. However, they typically fall short when it comes to attributing a *specific* contact form submission or conversion to a particular initial traffic source. This gap leaves a crucial piece of the marketing puzzle unsolved.
To address this, a lightweight first-touch attribution layer was developed. This solution is designed to be unobtrusive, requiring no cookies and no additional heavy JavaScript libraries. Its sole purpose is to tag each incoming visitor with the source from which they first arrived at the site. This allows for the reconstruction of the user's journey, even within a privacy-conscious, cookieless environment.
Implementing First-Touch Attribution in Local Storage
The core of this solution lies in capturing the first-touch attribution data at the earliest possible moment and storing it persistently but locally. First-touch attribution, by definition, means recording the very first interaction a user has with the site. This includes the external referrer (document.referrer), the specific landing page path where the user first arrived, and any UTM parameters appended to the URL. This information is captured only once per visitor. Subsequent visits or interactions will not overwrite this initial data, ensuring that the original source is preserved.
The chosen storage mechanism is the browser's localStorage. Unlike session storage, localStorage persists data even after the browser window is closed and reopened. This makes it ideal for tracking attribution across multiple sessions for a single user, without relying on cookies that can be deleted or blocked.
The implementation involves a JavaScript snippet that runs on the client-side. This snippet checks if attribution data already exists in localStorage. If it does not, the script proceeds to capture the relevant data points:
- Referrer: The value of
document.referreris recorded. This indicates the URL of the page that linked to the current page. - Landing Path: The initial path of the URL the user landed on is stored. This is often the root path or a specific campaign landing page.
- UTM Parameters: The script parses the URL for common UTM parameters such as
utm_source,utm_medium,utm_campaign,utm_term, andutm_content. These parameters are crucial for detailed campaign tracking.
All captured data is then serialized into a JSON string and stored in localStorage under a specific key, for example, 'attributionData'. This ensures that the data is organized and can be easily retrieved and parsed later.

Integrating with the Contact Form
The real value of this attribution layer is realized when a user completes a conversion action, such as submitting a contact form. The contact form's submission handler needs to be modified to retrieve the stored attribution data from localStorage. This data is then appended to the form submission payload.
When the form is submitted, the JavaScript code retrieves the JSON string from localStorage, parses it back into an object, and includes these attribution details as hidden fields or additional data in the submission to the backend. This could be sent directly to a CMS, a CRM, or a simple backend API endpoint.
For instance, if the attribution data stored was:
{
"referrer": "https://www.google.com/",
"landingPath": "/",
"utm_source": "google",
"utm_medium": "organic",
"utm_campaign": "spring_promo"
}
This object would be transformed into hidden input fields within the form or sent as part of a JSON payload to the server. This ensures that when the contact record is created or updated, it is automatically associated with the user's first-touch attribution information.
The surprising detail here is not the technical complexity, which is minimal, but the effectiveness of using a browser-native API like localStorage for a task traditionally handled by third-party cookies or complex server-side tracking. It demonstrates that robust analytics can be achieved even with strict privacy constraints.
Handling Edge Cases and Future Considerations
While this approach is effective, several edge cases and future considerations are worth noting:
- Data Persistence:
localStorageis tied to the browser and the specific domain. If a user clears their browser data, the attribution information will be lost. - Cross-Device Tracking: This method only tracks within a single browser on a single device. It cannot link a lead from a desktop visit to a mobile visit.
- Bots and Crawlers: The script should ideally include checks to avoid capturing attribution data from known bots or search engine crawlers, which could skew results.
- SPA Navigation: For Single Page Applications (SPAs) like Nuxt, the script needs to be robust enough to capture the initial landing path correctly, even if client-side routing occurs immediately after the initial page load. The current approach of capturing
document.referrerand initial URL parameters on script execution generally handles this well. - Data Volume: For sites with very high traffic, the continuous parsing and stringifying of
localStoragedata on every contact form submission is negligible. However, for extreme scale, optimizations might be considered.
The broader implication for developers building modern, privacy-focused web applications is that client-side storage offers a viable alternative for essential tracking needs. It allows businesses to retain critical insights into user acquisition without compromising user privacy, a balance that is increasingly becoming a requirement rather than a preference.
What remains unaddressed by this specific implementation is how to tie subsequent user interactions (beyond the first touch) to this initial attribution without cookies. While this solution expertly solves the first-touch problem, understanding the full user journey post-conversion would require additional, carefully considered strategies that respect privacy.
