How would you capture and persist UTM parameters for attribution?
Tests your grasp of state management and data persistence for analytics. A good answer covers capturing UTMs with JS, persisting them in a cookie, and associating them with a user record on the server during a conversion event.
What's really being asked
This question tests your ability to design a simple, robust data pipeline that connects a client-side event to a server-side record. It's not just about parsing a URL; it's about state management across a user's session. The interviewer is looking for your understanding of persistence mechanisms (cookies vs. local storage), their trade-offs, and how that data ultimately gets associated with a user entity in the backend database for later analysis.
The full answer
A complete answer describes a three-stage process. First, CAPTURE: on the initial page load, client-side JavaScript checks for UTM parameters in the URL using window.location.search and a parser like URLSearchParams. Second, PERSIST: the captured parameters are stored to survive navigation. The best choice is a first-party cookie with a defined expiration (e.g., 30 or 90 days), as it's automatically sent with subsequent server requests. Third, ASSOCIATE: when a key event occurs (e.g., user creation, purchase), the backend API reads the UTM data from the cookie included in the request and saves it to the relevant database record, such as a new users row or an events table.
The mistakes people make
A junior-level answer focuses only on the JavaScript parsing step. A major red flag is failing to mention a persistence strategy; storing the UTMs in a JavaScript variable means the data is lost on the next page load. Another mistake is suggesting Local Storage without explaining how that data would be retrieved and sent to the server, since unlike cookies, it is not sent automatically with HTTP requests. Finally, not mentioning an expiration policy for the stored data shows a lack of foresight about data hygiene and attribution windows.
What usually comes next
Expect questions about the trade-offs: "Why a cookie over Local Storage?" (Cookies are sent automatically but have a 4KB size limit; Local Storage is larger but requires manual JS to send). "How would you handle multiple campaigns?" (This opens a discussion on first-touch vs. last-touch attribution). "What is a reasonable expiration time for this cookie?" (Typically 30, 60, or 90 days, aligning with marketing campaign cycles). "How do browser privacy features like ITP affect this design?" (Shorter cookie lifespans may require moving to server-set cookies or other identifiers).
A concrete example
A user lands on your-site.com?utm_source=google. Your client-side script parses this and sets a first-party cookie: utm_data={"source":"google"}; max-age=2592000; path=/ (a 30-day expiration). The user browses three more pages. On the fourth page, they sign up. The POST /api/users request from the browser automatically includes the utm_data cookie. Your server-side code reads the cookie, parses the JSON, and writes attribution_source: 'google' into the new row in your users database table. The attribution is now permanently stored.
Interview question
To reliably attribute a user's conversion to UTM parameters after multiple page views, what is the recommended approach for persistence and association?
- a.Capture UTMs with client-side JavaScript, store them in Local Storage, and include them in the conversion API request using JavaScript.
- b.Capture UTMs on the server from the initial request and store them in the user's server-side session until conversion.
- c.Capture UTMs with client-side JavaScript, store them in a global JavaScript variable, and pass them with the conversion event.
- d.Capture UTMs with client-side JavaScript, store them in a first-party cookie, and have the backend read the cookie during conversion.Correct
Why? this is the answer
The card explicitly states that the best choice for persistence is a first-party cookie because it is automatically sent with subsequent server requests, allowing the backend to easily read and associate the data during a conversion event. Local Storage requires manual JavaScript to send data to the server, and JavaScript variables are lost on page navigation.
Just read this? Test yourself on what you have been reading.
Read the original → support.google.com
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on system design — each one lists the topics its interview covers.
See open roles