GoodAnalytics.Core.Partners.Attribution (GoodAnalytics v0.1.1)

Copy Markdown View Source

Shared referral partner attribution logic.

Provides atomic visitor partner attribution updates and helper functions used by the redirect and beacon click flows.

Summary

Functions

Sets the referral cookie on a conn. Returns conn unchanged if context is nil.

Merges referral context into event attrs. Returns attrs unchanged if context is nil.

Atomically updates visitor partner attribution.

Functions

maybe_set_cookie(conn, context)

Sets the referral cookie on a conn. Returns conn unchanged if context is nil.

merge_into_attrs(attrs, context)

Merges referral context into event attrs. Returns attrs unchanged if context is nil.

set_partner_attribution(visitor_id, context)

Atomically updates visitor partner attribution.

Last-touch fields are updated unconditionally. First-touch fields are written only when first_partner_id IS NULL, using a conditional update_all with a WHERE guard. This makes first-touch atomic — if two concurrent requests both see nil, only one UPDATE will match the IS NULL condition in the database, preventing double-write races.