Skip to content

Conversation

@rockwellll
Copy link
Collaborator

This PR makes Hellotext UTM-aware to ensure proper attribution is handled and be fair when a touchpoint was from a campaign outside of Hellotext.

UTM object

There is a new UTM object that encapsulates the logic of parsing and storing (in cookies) the UTM params present in the URL.

constructor() {
const urlSearchParams = new URLSearchParams(window.location.search)
const utmsFromUrl = {
source: urlSearchParams.get('utm_source'),
medium: urlSearchParams.get('utm_medium'),
campaign: urlSearchParams.get('utm_campaign'),
term: urlSearchParams.get('utm_term'),
content: urlSearchParams.get('utm_content'),
}
if (utmsFromUrl.source && utmsFromUrl.medium) {
const cleanUtms = Object.fromEntries(
Object.entries(utmsFromUrl).filter(([_, value]) => value),
)
Cookies.set('hello_utm', JSON.stringify(cleanUtms))
}
}

Additionally, it provides a current method that parses the value from the Cookies if present,

get current() {
try {
return JSON.parse(Cookies.get('hello_utm')) || {}
} catch (e) {
return {}
}
}

Page object

This is related to what we discussed in #24, by passing all the existing page data back to Hellotext instead of just the URL. Now, in-addition to the URL, we collect the current page's title and path and pass it along the UTM in the tracking data.

get trackingData() {
return {
page: {
url: this.url,
title: this.title,
path: this.path,
},
utm_params: this.utmParams,
}
}

This lifts the burden on Hellotext to making another request to the URL to get the page's metadata.

@rockwellll rockwellll merged commit 17dde13 into main Sep 13, 2025
3 checks passed
@rockwellll rockwellll deleted the utm-awareness branch September 13, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants