We want to set tracking cookie to check how many users we are getting through various marketing campaigns. On each campaign URL of our website, we add following query string parameters:- utm_source, utm_medium and utm_campaign.
Sample URL:- https://example.com/?utm_source=facebook&utm_medium=cpc&utm_campaign=jan
Anytime, we get request from any URL on our server, we check:
- If url has utm_* parameters, we save those in the cookie.
- If there's no such utm_* parameters in the url and If referer host is our website i.e. https://example.com/, we save that in cookie for 6 months.
- If there's no such utm_* parameters in the url and referer is one of search engine, we save search engine name in cookie.
and we have few more similar conditions.