I am using MixPanel with a Laravel implementation. I have set up logic to set the 'UTM Source' based on our business requirements. This includes; $referrer, $social, $email, $organic, $network and $facebook_ad. These are working well and as expected to track our needs.
The default value for 'UTM Source' is set to '$direct'. So if none of the other conditions is set above it will always be set to '$direct'
This code is run on every page load of the website, including internal navigation. So if a user does the following:
/page-a then navigates internally to /page-b, both of these will be attributed as '$direct'.
My question is should the default be blank and then only set $direct under certain conditions?
I say the answer is either no, or $direct only needs to be set on the first arrival to the website. If it's the latter, how would this be accomplished in Laravel? i.e. set this only if the user returns to the site after x hours?
How would the MixPanel JS implementation handle this use case?
Update, with help from @BNazaruk. We have found the following information from MixPanel's website:
https://docs.mixpanel.com/docs/tracking/how-tos/tracking-utm-tags
"An initial referrer is equal to $direct when a user first lands on a site without being referred by another website."
So my updated question is how long should we wait to set direct again after the user has first landed on the website? 1-hour / 1-day / 1-week / indefinitely?
I'd guess in Laravel we'd need to set a cookie to track this time. When the cookie expires, we set $direct again.
Short answer: in 99% of cases, backend (Laravel in this case) should know nothing about UTM params and should not ever touch them. Read or write.
An analytics system has a series of methods by which it determines what channel to assign to every hit, essentially. It mostly uses referrers and query params and then assigns the channel it concluded from the first hit to all the hits in a session. This channel propagation normally happens on the mixpanel's backend. An analytics system typically assigns Direct when it doesn't have a referrer or query param to rely upon.
UTM parameters are meant as a simple non-technical override for the default behavior when a non-technical person (like a marketeer) wants to publish an ad link on typically a partner's site. If they publish that link with no utm params, the analytics system will recognize that traffic as referral traffic and assume it's not paid for. Now to change the channel from referral to paid, there are utm params for that marketeer to populate.
Another typical example is using the UTM parameters in emails. To help the analytics system to distinguish the direct from email channels. Otherwise all or most of email traffic will be seen as direct. Also UTMs are useful to indicate which email in particular resulted in the traffic.
As you can see, none of these examples implies any attention from front-end resources, not even mentioning the back-end.
Now you have more context about your case. You might be exceptionally requiring backend to set UTMs, but most likely it's a dire misunderstanding.