Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/providers/umami.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ umami:
domain: your-domain.com
websiteId: ''
endpointUrl: https://umami.your-domain.com
distinctIdParameter: ''
templates:
tag: ''
googleConsent:
Expand All @@ -29,6 +30,7 @@ umami:
| `domain` | Optional override for the event's domain field. |
| `websiteId` | Umami website ID. |
| `endpointUrl` | Base URL of your Umami instance. |
| `distinctIdParameter` | Optional event data key whose value the tag sends as the distinct ID. See [Distinct ID](#distinct-id). |
| `googleConsent.mode` | Defaults to `analytics_storage`. |
| `serverContainer.packages` | Events to forward. |
| `templates.tag` | Path to a custom tag template file. Empty (default) provisions the embedded template. |
Expand All @@ -43,3 +45,11 @@ Events without `Params` fields send no event data.

The tag sends the first address of the `ip_override` event data value as `payload.ip`.
This requires Umami v2.10.0 or later. If `payload.ip` is set, Umami v2.17.0 and later resolve the location from the IP and ignore the `cf-ip*` location headers.

## Distinct ID

With `distinctIdParameter` set, the tag reads that key from the server container event data and sends its value as `payload.id`.
The tag omits `payload.id` when the setting is empty or the value is missing.
Umami v3.4.0 and later add the distinct ID to the session hash, so visitors with the same IP and user agent get separate sessions.
The distinct ID does not join sessions across IP addresses, user agents or salt rotations.
Send the same value on every event of a visitor. An event without it starts a separate session.
3 changes: 3 additions & 0 deletions pkg/config/umami.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type Umami struct {
Domain string `json:"domain" yaml:"domain"`
WebsiteID string `json:"websiteId" yaml:"websiteId"`
EndpointURL string `json:"endpointUrl" yaml:"endpointUrl"`
// Event data key whose value the tag sends as the Umami distinct ID (payload.id), e.g. a first-party session ID.
// Umami v3.4.0 and later separate sessions by it. Empty (default) sends no distinct ID.
DistinctIDParameter string `json:"distinctIdParameter,omitempty" yaml:"distinctIdParameter,omitempty"`
// Custom tag template settings
Templates UmamiTemplates `json:"templates" yaml:"templates"`
// Google Consent settings
Expand Down
8 changes: 8 additions & 0 deletions pkg/provider/umami/server/tag/umami.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func NewUmami(name string, cfg config.Umami, template *tagmanager.CustomTemplate
},
}

if cfg.DistinctIDParameter != "" {
parameter = append(parameter, &tagmanager.Parameter{
Key: "distinctIdParameter",
Type: "template",
Value: cfg.DistinctIDParameter,
})
}

if len(params) > 0 {
var list []*tagmanager.Parameter

Expand Down
33 changes: 33 additions & 0 deletions pkg/provider/umami/server/tag/umami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,36 @@ func TestNewUmami(t *testing.T) {
})
}
}

func TestNewUmami_DistinctIDParameter(t *testing.T) {
t.Parallel()

find := func(tag *tagmanager.Tag, key string) *tagmanager.Parameter {
for _, p := range tag.Parameter {
if p.Key == key {
return p
}
}

return nil
}

t.Run("set", func(t *testing.T) {
t.Parallel()

got := tag.NewUmami("page_view", config.Umami{DistinctIDParameter: "session_id"}, &tagmanager.CustomTemplate{}, nil)

p := find(got, "distinctIdParameter")
require.NotNil(t, p)
assert.Equal(t, "template", p.Type)
assert.Equal(t, "session_id", p.Value)
})

t.Run("empty", func(t *testing.T) {
t.Parallel()

got := tag.NewUmami("page_view", config.Umami{}, &tagmanager.CustomTemplate{}, nil)

assert.Nil(t, find(got, "distinctIdParameter"))
})
}
14 changes: 14 additions & 0 deletions pkg/provider/umami/server/template/umamidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ ___TEMPLATE_PARAMETERS___
}
],
"defaultValue": 1000
},
{
"type": "TEXT",
"name": "distinctIdParameter",
"displayName": "Distinct ID Parameter (Optional)",
"simpleValueType": true,
"help": "Event data key whose value is sent as the Umami distinct ID (payload.id)"
}
]
},
Expand Down Expand Up @@ -144,6 +151,13 @@ if (pageLocation) {
umamiEvent.payload.ip = ip;
}

if (data.distinctIdParameter) {
const distinctId = eventData[data.distinctIdParameter];
if (distinctId) {
umamiEvent.payload.id = makeString(distinctId);
}
}

const umamiData = getEventParameters(eventData, data.eventParameters);
if (umamiData) {
umamiEvent.payload.data = umamiData;
Expand Down
4 changes: 4 additions & 0 deletions sesamy.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,10 @@
"endpointUrl": {
"type": "string"
},
"distinctIdParameter": {
"type": "string",
"description": "Event data key whose value the tag sends as the Umami distinct ID (payload.id), e.g. a first-party session ID.\nUmami v3.4.0 and later separate sessions by it. Empty (default) sends no distinct ID."
},
"templates": {
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.UmamiTemplates",
"description": "Custom tag template settings"
Expand Down
2 changes: 2 additions & 0 deletions sesamy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ umami:
websiteId: ''
# Endpoint url of the umami api
endpointUrl: https://umami.your-domain.com
# Optional event data key whose value is sent as the Umami distinct ID (payload.id)
distinctIdParameter: ''
# Google Consent settings
googleConsent:
# Enable consent mode
Expand Down
Loading