Friend-source Tracking
Overview
Friend Track answers the question "where did this friend come from?" Administrators create a campaign-specific link or QR code; when a user adds the OA as a friend through that link, the system records the event and can immediately write the acquisition source into that friend's attributes.
It also supports sub-level ref IDs — staff codes, branch codes, or media codes — which can be uploaded as a batch in advance, allowing attribution to be broken down more finely than the campaign level.
Core Data Structure
friend_track_campaign (model FriendTrackCampaign)
name,description,token(unique, used to build the add-friend link), andstatus(string, defaultactive)attribute_configJSONB — which values to write into the user's attributes when they arrive through this campaignref_attribute_key— the attribute key that stores the ref IDref_upload_statusJSONB — the status of the ref batch upload- foreign keys
line_oa_id→line_oa.idandorganization_id→organization.id, bothON DELETE Restrict
It has 1 : N relations to friend_track_event, friend_track_ref, and content_page,
since a content page can carry an add-friend button for the campaign.
friend_track_event (model FriendTrackEvent)
Records what actually happened.
campaign_idFK (ON DELETE CASCADE),line_user_id,event_type- a profile snapshot at the time:
display_nameandpicture_url ref_id— the sub-level ref carried by the link- indexes on
(campaign_id),(line_user_id, line_oa_id), and(event_type, campaign_id)
friend_track_ref (model FriendTrackRef)
The registry of permitted refs, with unique (campaign_id, ref_id) and a foreign key to
friend_track_campaign using ON DELETE CASCADE.
Trigger
friend_track_event_insert_notify (AFTER INSERT) calls
notify_friend_track_event_insert(), emitting pg_notify('friend_track_event_inserted', ...).
Historical note — this trigger was once missing from the database: the function existed
but the trigger itself did not, leaving the channel entirely silent. It was restored on
24 July 2026 in manual-sql/5.sql.
Related Files
prisma/schema.prisma:1388— modelFriendTrackCampaignprisma/schema.prisma:1418— modelFriendTrackEventprisma/schema.prisma:1439— modelFriendTrackRefmanual-sql/5.sql— the function and trigger, with comments explaining the fixschema-dumps/2026-07-24/schema.sql:1869,:1912,:1950
Connections to Other Services
- webhook-go — receives follow events carrying a ref and inserts
friend_track_event - worker-go — listens on
friend_track_event_insertedto write attributes perattribute_config, add the user to audiences, and fire workflows - cms-api-go — campaign creation, ref batch uploads, and channel-level reporting through
the
friend-trackmodule - client-api-go — content pages carrying the campaign's add-friend button
Related domains: LINE Friends, Attribute Master, Content Pages, Event Outbox