Skip to content
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ Hellotext.removeEventListener(eventName, callback)
| Event | When it fires | Callback payload |
| ------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `session-set` | The session value is set, including when an existing session is restored during initialization. | The current session value, also available as `Hellotext.session`. |
| `utm-set` | UTM parameters are saved. | A JSON string containing the saved UTM parameters and `observed_at`. Use `JSON.parse` to read it as an object. |
| `utm-set` | The UTM parameters the visitor arrived with are saved. | A JSON string containing the saved UTM parameters and `observed_at`. Use `JSON.parse` to read it as an object. |

UTM parameters on links inside the site (a store's own popup, banner or menu link) do not replace the ones the visitor arrived with and do not fire `utm-set`. They are kept apart and sent with events as `internal_utm_params`. Hellotext's own UTMs always count as an arrival.

See [Understanding Sessions](/docs/sessions.md) and [Tracking Events](/docs/tracking.md).

Expand Down
23 changes: 23 additions & 0 deletions __tests__/models/page_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,29 @@ describe('Page', () => {
utm_params: {}
})
})

it('adds the in-site UTM when the visitor clicked one of the site\'s own UTM links', () => {
mockUtm.current = { source: 'google', medium: 'cpc' }
mockUtm.internal = { source: 'pop_up_tv', medium: 'pop_up_tv', observed_at: '2026-10-24T18:00:00.000Z' }

const page = new Page()

expect(page.trackingData).toEqual({
page: {
url: 'https://example.com/current-page?param=value',
title: 'Current Page Title',
path: '/current-page'
},
utm_params: { source: 'google', medium: 'cpc' },
internal_utm_params: { source: 'pop_up_tv', medium: 'pop_up_tv', observed_at: '2026-10-24T18:00:00.000Z' }
})
})

it('leaves the in-site UTM out when there is none', () => {
mockUtm.internal = {}

expect(new Page().trackingData).not.toHaveProperty('internal_utm_params')
})
})

describe('domain getter', () => {
Expand Down
Loading
Loading