Skip to main content

Looking Up Users from Tracking Log (Tracking LINE Users)

Overview

This module exposes a single endpoint for finding LINE users by the tracking keys the system records — the log of who tapped what and when. It is used whenever a behaviour needs to be traced back to actual people, answering questions such as "who clicked link X in campaign Y?"

One thing to be aware of: this endpoint is a POST with an untyped body, because the original TypeScript implementation accepted it that way. That choice has consequences for error behaviour, described below.

Business Flow

  1. cms-web sends POST /api/tracking-line-users with a body that must contain a trackingKeys array.
  2. The service reads lineOaId from CLS and forwards it to the repository along with the submitted body.
  3. The repository searches tracking_line_users for the given tracking keys and joins back to line_user to retrieve the user records.
  4. The result is returned as a pass-through — no reshaping is applied, matching the legacy implementation.
  5. A preserved error case — if trackingKeys is missing or is not an array, the original TypeScript code would read .length on undefined and raise a TypeError. The Go port reproduces this with an error reading Cannot read properties of undefined (reading 'length'), and the controller responds with HTTP 500 and the APP_000 code. The controller decodes the body into a findLineUsersPayload carrying a trackingKeysUsable flag specifically to detect this case.

Key Files & Functions

The code lives in internal/modules/trackinglineusers/, split across controller.go and service.go.

MethodRouteHandlerPolicy
POST/api/tracking-line-userssvc.getListHandlerreadAll tracking-log

The route is registered on the authed group, which enforces JWT, but has no ModuleGate.

The variable governing the error behaviour is errTrackingKeysNotIterable in service.go.

Connections to Other Services

  • Permissions — requires the global JwtAuth, which mandates a lineOaId. PolicyModuleTrackingLog is metadata only and is not yet enforced.
  • Tablestracking_line_users and line_user.
  • CLSlineOaId from the request context scopes the query.
  • Related modules — Tracking Link, which creates the tracking tokens; Campaign Management, which generates tracking events; and LINE User Management.