Self-Describing Events Implementation

Hi! I have a website that I’m locally hosting with a button, and I’ve tried to implement a self-describing event for a button_click event that should fire when the button is clicked. Here is my tracker code:

snowplow(‘trackSelfDescribingEvent’, {
event: {
schema: ‘http://localhost:8083/schemas/button_click.json’,
data: {
buttonId: “my-button-id”,
buttonText: “Click Me”,
pageUrl: ‘http://localhost:8083
}
}
});

And here is the custom schema I want to use for validation:

{
“$schema”: “http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#”,
“self”: {
“vendor”: “com.snowplowanalytics”,
“name”: “button_click”,
“format”: “jsonschema”,
“version”: “1-0-0”
},
“type”: “object”,
“properties”: {
“buttonId”: {
“type”: “string”
},
“buttonText”: {
“type”: “string”
},
“pageUrl”: {
“type”: “string”
}
},
“required”: [“buttonId”, “buttonText”, “pageUrl”],
“additionalProperties”: false
}

I understand that I need to include the vendor properties in somewhere, since my schema has to contain ‘iglu:’, but I don’t know how to do it properly. This schema is also stored locally in the /schemas/ directory, I don’t plan on uploading it to iglu.

I’d appreciate any help!

Hi @sven,

The schema property in the event is the place where you give the URI of the schema including it’s vendor, name, and version (you can read the docs here).

snowplow('trackSelfDescribingEvent', {
  event: {
    schema: 'iglu:com.snowplowanalytics/button_click/jsonschema/1-0-0',
    data: {
        buttonId: "my-button-id",
        buttonText: "Click Me",
        pageUrl: "http://localhost:8083"
    }
  }
});

Note, for a custom schema, it’s a good practice to use a schema vendor such as you domain (e.g., com.sven) instead of the Snowplow one (com.snowplowanalytics) to avoid confusion.

Thanks! I did try this, but my events are still bad. For reference, I used the instructions for testing custom schema in snowplow micro and ran my command like this:

docker run -p 9090:9090
–mount type=bind,source=$(pwd)/schemas,destination=/config/iglu-client-embedded/schemas
snowplow/snowplow-micro:1.7.2

My domain is com.example/button_click/jsonschema/1-0-0. I also changed the schema file to reflect that.

Can you send the validation error that you see in the bad events (endpoint http://localhost:9090/micro/bad) for us to check?

Sure, here it is:

{
“collectorPayload”: {
“api”: {
“vendor”: “com.snowplowanalytics.snowplow”,
“version”: “tp2”
},
“querystring”: ,
“contentType”: “application/json”,
“body”: “{"schema":"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4","data":[{"e":"ue","eid":"f38d84e9-42ad-4ccd-b6c2-2aba4e0c1462","tv":"js-3.13.0","tna":"cf","aid":"my-app-id","p":"web","cookie":"1","cs":"windows-1252","lang":"en-US","res":"1280x800","cd":"24","tz":"America/Phoenix","dtm":"1688861906151","vp":"725x689","ds":"725x689","vid":"42","sid":"13db161a-a999-47bd-a855-521a8e060882","duid":"2a64c3f3-8d7a-4b80-b81b-865ed530af1f","url":"http://localhost:8083/\“,\“ue_pr\”:\”{\"schema\":\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\",\"data\":{\"schema\":\"iglu:com.snowplowanalytics/button_click/jsonschema/1-0-0\",\"data\":{\"eventType\":\"button_click\",\"buttonId\":\"my-button-id\",\"buttonText\":\"Click Me\",\"pageUrl\":\"http://localhost:8083\"}}}","co":"{\"schema\":\"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0\",\"data\":[{\"schema\":\"iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0\",\"data\":{\"id\":\"8d0b25b5-9674-427a-ab3e-35333f98f45c\"}},{\"schema\":\"iglu:org.w3/PerformanceTiming/jsonschema/1-0-0\",\"data\":{\"navigationStart\":1688861826646,\"redirectStart\":0,\"redirectEnd\":0,\"fetchStart\":1688861826647,\"domainLookupStart\":1688861826647,\"domainLookupEnd\":1688861826647,\"connectStart\":1688861826647,\"secureConnectionStart\":0,\"connectEnd\":1688861826647,\"requestStart\":1688861826649,\"responseStart\":1688861826651,\"responseEnd\":1688861826652,\"unloadEventStart\":1688861826654,\"unloadEventEnd\":1688861826654,\"domLoading\":1688861826654,\"domInteractive\":1688861826660,\"domContentLoadedEventStart\":1688861826660,\"domContentLoadedEventEnd\":1688861826660,\"domComplete\":1688861826670,\"loadEventStart\":1688861826670,\"loadEventEnd\":1688861826670}}]}","stm":"1688861906153"}]}”,
“source”: {
“name”: “snowplow-micro-1.7.1-stdout$”,
“encoding”: “UTF-8”,
“hostname”: “localhost”
},
“context”: {
“timestamp”: “2023-07-09T00:18:26.217Z”,
“ipAddress”: “172.17.0.1”,
“useragent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36”,
“refererUri”: “http://localhost:8083/”,
“headers”: [
“Timeout-Access: ”,
“Host: localhost:8081”,
“Connection: keep-alive”,
“sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"”,
“sec-ch-ua-platform: "Windows"”,
“sec-ch-ua-mobile: ?0”,
“User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36”,
“Accept: /”,
“Origin: http://localhost:8083”,
“Sec-Fetch-Site: same-site”,
“Sec-Fetch-Mode: cors”,
“Sec-Fetch-Dest: empty”,
“Referer: http://localhost:8083/”,
“Accept-Encoding: gzip, deflate, br”,
“Accept-Language: en-US, en;q=0.9”,
“Cookie: micro=26500323-2adf-4a56-a88e-309753992f82; _sp_ses.1fff=; _sp_id.1fff=2a64c3f3-8d7a-4b80-b81b-865ed530af1f.1687544513.42.1688861906.1688772567.13db161a-a999-47bd-a855-521a8e060882.5d5f4faf-1b6e-4a46-9269-73109dfa02c6.55231754-c931-4f9f-8370-945ac38216d4.1688861801713.11",
“application/json”
],
“userId”: “26500323-2adf-4a56-a88e-309753992f82”
}
},
“rawEvent”: null,
“errors”: [
“Error while extracting event(s) from collector payload and validating it/them.”,
"{"schema":"iglu:com.snowplowanalytics.snowplow.badrows/tracker_protocol_violations/jsonschema/1-0-0","data":{"processor":{"artifact":"snowplow-micro","version":"1.7.1"},"failure":{"timestamp":"2023-07-09T00:18:26.523875Z","vendor":"com.snowplowanalytics.snowplow","version":"tp2","messages":[{"schemaKey":"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4","error":{"error":"ResolutionError","lookupHistory":[{"repository":"Iglu Central","errors":[{"error":"NotFound"}],"attempts":7,"lastAttempt":"2023-07-09T00:18:26.522Z"},{"repository":"Iglu Client Embedded","errors":[{"error":"NotFound"}],"attempts":1,"lastAttempt":"2023-07-09T00:16:41.851Z"}]}}]},"payload":{"vendor":"com.snowplowanalytics.snowplow","version":"tp2","querystring":[],"contentType":"application/json","body":"{\"schema\":\"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4\",\"data\":[{\"e\":\"ue\",\"eid\":\"f38d84e9-42ad-4ccd-b6c2-2aba4e0c1462\",\"tv\":\"js-3.13.0\",\"tna\":\"cf\",\"aid\":\"my-app-id\",\"p\":\"web\",\"cookie\":\"1\",\"cs\":\"windows-1252\",\"lang\":\"en-US\",\"res\":\"1280x800\",\"cd\":\"24\",\"tz\":\"America/Phoenix\",\"dtm\":\"1688861906151\",\"vp\":\"725x689\",\"ds\":\"725x689\",\"vid\":\"42\",\"sid\":\"13db161a-a999-47bd-a855-521a8e060882\",\"duid\":\"2a64c3f3-8d7a-4b80-b81b-865ed530af1f\",\"url\":\"http://localhost:8083/\\\“,\\\“ue_pr\\\”:\\\”{\\\"schema\\\":\\\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\\\",\\\"data\\\":{\\\"schema\\\":\\\"iglu:com.snowplowanalytics/button_click/jsonschema/1-0-0\\\",\\\"data\\\":{\\\"eventType\\\":\\\"button_click\\\",\\\"buttonId\\\":\\\"my-button-id\\\",\\\"buttonText\\\":\\\"Click Me\\\",\\\"pageUrl\\\":\\\"http://localhost:8083\\\"}}}\",\"co\":\"{\\\"schema\\\":\\\"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0\\\",\\\"data\\\":[{\\\"schema\\\":\\\"iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0\\\",\\\"data\\\":{\\\"id\\\":\\\"8d0b25b5-9674-427a-ab3e-35333f98f45c\\\"}},{\\\"schema\\\":\\\"iglu:org.w3/PerformanceTiming/jsonschema/1-0-0\\\",\\\"data\\\":{\\\"navigationStart\\\":1688861826646,\\\"redirectStart\\\":0,\\\"redirectEnd\\\":0,\\\"fetchStart\\\":1688861826647,\\\"domainLookupStart\\\":1688861826647,\\\"domainLookupEnd\\\":1688861826647,\\\"connectStart\\\":1688861826647,\\\"secureConnectionStart\\\":0,\\\"connectEnd\\\":1688861826647,\\\"requestStart\\\":1688861826649,\\\"responseStart\\\":1688861826651,\\\"responseEnd\\\":1688861826652,\\\"unloadEventStart\\\":1688861826654,\\\"unloadEventEnd\\\":1688861826654,\\\"domLoading\\\":1688861826654,\\\"domInteractive\\\":1688861826660,\\\"domContentLoadedEventStart\\\":1688861826660,\\\"domContentLoadedEventEnd\\\":1688861826660,\\\"domComplete\\\":1688861826670,\\\"loadEventStart\\\":1688861826670,\\\"loadEventEnd\\\":1688861826670}}]}\",\"stm\":\"1688861906153\"}]}","collector":"snowplow-micro-1.7.1-stdout$","encoding":"UTF-8","hostname":"localhost","timestamp":"2023-07-09T00:18:26.217Z","ipAddress":"172.17.0.1","useragent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36","refererUri":"http://localhost:8083/\",\“headers\”:[\"Timeout-Access: ","Host: localhost:8081","Connection: keep-alive","sec-ch-ua: \"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"","sec-ch-ua-platform: \"Windows\"","sec-ch-ua-mobile: ?0","User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36","Accept: /","Origin: http://localhost:8083","Sec-Fetch-Site: same-site","Sec-Fetch-Mode: cors","Sec-Fetch-Dest: empty","Referer: http://localhost:8083/\",\"Accept-Encoding: gzip, deflate, br","Accept-Language: en-US, en;q=0.9","Cookie: micro=26500323-2adf-4a56-a88e-309753992f82; _sp_ses.1fff=
; _sp_id.1fff=2a64c3f3-8d7a-4b80-b81b-865ed530af1f.1687544513.42.1688861906.1688772567.13db161a-a999-47bd-a855-521a8e060882.5d5f4faf-1b6e-4a46-9269-73109dfa02c6.55231754-c931-4f9f-8370-945ac38216d4.1688861801713.11","application/json"],"networkUserId":"26500323-2adf-4a56-a88e-309753992f82"}}}”
]
}