Skip to main content

I recently implemented Web Tracking on my Javascript instance of Amplitude for our website. Web Tracking allows us to grab things like UTM parameters or Referring Domain information to help us understand how users started a session on our platform. I should also mention my platform is a B2B SaaS platform.

 

The problem I am having is that those details (e.g. “utm_campaign”, “utm_source”) are set as user properties and persist until something else replaces them. However, the purpose of collecting referring details such at UTMs are to help me understand what drove a user to our platform… implicitly defined as “for that session”. 

 

The problem with the way this is currently implemented is that if I have a user come to my platform as a result of opening an email that I sent to drive them to my site today, and they come back to my site directly tomorrow, or next week… that first email campaign continues to “get the credit”. Remember that this is a SaaS platform, so what I really want to know is “are my emails driving usage” (in this case) -- as opposed to how UTMs may be used for D2C brands or ecommerce.

 

So, my question… is there a way to default these UTM user properties to be reset with each session? Or perhaps is there another (better) way to track “where did this session come from”? I find fault with the suggestion of using a “Session Started” event because then exploring all events that stemmed from a session which started as a result of an email click proves to be more difficult on the platform than it needs to be. I look forward to your ideas! 

 

PS -- here’s some screengrabs of the events with UTMs persisted when I would only like them in the events associated to the sessions that actually came from that campaign. Note: `initial_` parameters I don’t care about -- those are done correctly IMO.

 

 

Hey @jimmy,

 

If you use set instead of setOnce on utm_medium, utm_campaign, and utm_source, the values will overwrite each time. Here’s some additional documentation on it: https://developers.amplitude.com/docs/javascript#web-attribution


@SheenaGreen can you point me to the specific line in the url you sent over? https://developers.amplitude.com/docs/javascript#web-attribution 


The option for using set vs setOnce does not seem to appear on the Web Attribution section of that document as a valid option. What it says is…

In Amplitude, once you set the includeUtm option to true, the JavaScript SDK will automatically pull UTM parameters from the referring URL and include them as user properties on all of the relevant events.

It then later says: 

UTM parameters are captured once per session by default and occurs when the user loads your site and the Amplitude SDK for the first time.

Only “initial UTM” parameters are captured using the setOnce option. 

 

So… my question still stands, how do I get UTM parameters to only be set during sessions that came from a valid UTM? And inherently, how do I reset them when there is no UTM parameters in the URL that starts a session on our platform? 

 

Again, if there’s a better way to do this… I’m all ears.


@jimmy you’re right, the behavior to setOnce on initial_utms and set the non-initial utms each session should be automatic. 

 

What I’m noticing is the non-initial utms (medium, source, campaign) only update when there is a new value when the SDK initializes. If the value is null when the SDK initializes, the previous values persist. I’m not sure if this is the expected behavior, I believe it is. 

 

We send a custom Landing Page event each time we detect a new Amplitude session, and this event includes medium, source, and campaign as properties. We run a custom function in GTM to set these values, so when the values are null, we classify this traffic as Direct in the event properties. We also have logic in there to identify label Organic traffic. This is one way we are able to look at behavior by most recent traffic source. Sorry I couldn’t help more!


Hi @jimmy ,

 

I believe @SheenaGreen highlighted everything needed here! I do want to also point out the Identify API here which contains set and setOnce and this should be able to help you with your UTM parameters and to only set during sessions from a valid UTM.


@SheenaGreen I very much appreciate the follow up. In terms of expected behavior, you’re probably right -- it’s most likely intended to not replace those parameters unless there’s a non-null value to replace it. I think the only valid way to do this is to trigger a new “Session Started” event and hack the properties.

 

@Denis Holmes I’m still not sure my actual question has been answered. And that question is: is there an Amplitude-provided config that resets the UTM-related user properties for each session (including null as an option)? What I think you are suggesting is that I manually set, clear, and re-set the UTM user properties manually -- which would defeat the use of the web attribution features, as documented here: https://developers.amplitude.com/docs/javascript#web-attribution 

 

Perhaps you can elaborate on how one might use the Identify API to do what I am looking to do? Or are you suggesting I skip using the web attribution includeUtm configuration and just set and unset my UTM-related user properties manually? If that is true, would it be possible to share the source code used around includeUtm so I can configure it to set those properties to null if a non-null value is not identified? Thank you in advance.


Thank you @jimmy for following up here. I’m also looping in @ning.chang who will be able to take a closer look. In the meantime, have a great weekend! 😀

 


Hi @jimmy,

 

If tracking is enabled, then the SDK will set the values as user properties (e.g. referrer or utm_source) once per session (this is last touch attribution). The SDK will also save the initial values using a setOnce operation (e.g. initial_referrer or initial_utm_source), and once set that value will never change (this is first touch attribution).

 

Note: By default, the SDK will only save the values at the start of the session. For example, if a user lands on your site with an initial set of UTM parameters and triggers some flow that causes them to land on your site again with a different set of UTM parameters within the same Amplitude session, then that second set will not be saved. You can set the configuration option saveParamsReferrerOncePerSession to false to remove that restriction so that the SDK will always capture any new values from the user.

 

Note: By default, the SDK will carry over existing UTM Parameters and Referrer values at the start of a new session. For example, if a users session expires, the SDK will map the user's Referrer and UTM Parameters to existing values. To reset those values to null upon instantiating a new session, set unsetParamsReferrerOnNewSession to true.

 

So I would be sure to use the above and that should help you with your UTM tracking.


 

Note: By default, the SDK will carry over existing UTM Parameters and Referrer values at the start of a new session. For example, if a users session expires, the SDK will map the user's Referrer and UTM Parameters to existing values. To reset those values to null upon instantiating a new session, set unsetParamsReferrerOnNewSession to true.

 

@Denis Holmes Okay now we’re talking! Thank you for sharing this follow up! I did not see anything related to the unsetParamsReferrerOnNewSession parameter in the Web Attribution portion of the documentation. Then, I found what you were referring to under “Advanced Topics” (← in case anyone else needs to do this).

 

I believe this should fix my issue. I’m going to chat with my engineers and see about getting this installed. Many thanks on your diligence to follow up with me.  😃


My pleasure @jimmy! Glad you got it sorted! @Jeremie Gluckman Can you mark Sheena’s answer as correct if you get the chance? Cannot seem to do it? Thank you!

Also @jimmy , some Javascript SDK options are available here. Might be helpful for your Engineers :)


Reply