snowplow / snowplow-javascript-tracker

Snowplow event tracker for client-side and server-side JavaScript. Add analytics to your websites, web apps and servers.
http://snowplowanalytics.com
BSD 3-Clause "New" or "Revised" License
555 stars 222 forks source link

Invalid `client_session` entity with `stateStorageStrategy: 'none'` #1298

Open jethron opened 8 months ago

jethron commented 8 months ago

Describe the bug The client_session entity requires that the userId value be provided as a string matching a pattern (^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$|^[0-9a-f]{16}$) and the sessionId be provided as a UUID. In the JS tracker, this value is usually populated with what would be the Domain User ID value and Session ID values, respectively. To accommodate this, when creating the client_session entity, the tracker does a few compatibility checks for anonymousTracking to ensure it produces valid data.

Mostly the checks are:

However, if stateStorageStrategy is none (via initial configuration or toggling via enableAnonymousTracking) but anonymousTracking is not enabled (possible in the latter case by providing options: false), these checks will pass, but the tracker will populate userId and sessionId with an empty string as the respective identifiers are not available. The resulting event will fail schema validation.

To Reproduce

snowplow('newTracker', 'anon', 'http://localhost:9090', {stateStorageStrategy: 'none', contexts: {session: true}});
snowplow('trackPageView');

Expected behavior Valid event produced by omitting client_session entity or falling back to nil UUID for user/session IDs.

Screenshots Event fails validation on client_session entity:

{
  "schemaKey" : "iglu:com.snowplowanalytics.snowplow/client_session/jsonschema/1-0-2",
  "error" : {
    "error" : "ValidationError",
    "dataReports" : [
      {
        "message" : "$.sessionId:  is an invalid uuid",
        "path" : "$.sessionId",
        "keyword" : "uuid",
        "targets" : [
          "",
          "uuid"
        ]
      },
      {
        "message" : "$.userId: does not match the regex pattern ^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$|^[0-9a-f]{16}$",
        "path" : "$.userId",
        "keyword" : "pattern",
        "targets" : [
          "^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$|^[0-9a-f]{16}$"
        ]
      }
    ]
  }
}

Additional context See Zendesk #40198