Always fall in "bad" for custom context

Hi guys,

I have been stuck with the snowplow mini with passing event containing custom context data.

For test case, I use the the snowplow link_click schema for the context just incase if there are other factor mess up the schema validation, e.g. iglu server not setup properly.

Here is the context field:
‘co’ => ‘{“schema”:“iglu:com.snowplowanalytics.snowplow\/contexts\/jsonschema\/1-0-1”,“data”:{“schema”:“iglu:com.snowplowanalytics.snowplow\/link_click\/jsonschema\/1-0-1”,“data”:{“elementId”:“1234”,“targetUrl”:“http:\/\/www.google.com”}}}’,

Schema is https://github.com/snowplow/iglu-central/blob/master/schemas/com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1

However, it always falls to the bad bucket with this error:

{“level”:“error”,“message”:“error: instance type (object) does not match any allowed primitive type (allowed: [“array”])\n level: “error”\n schema: {“loadingURI”:”#",“pointer”:""}\n instance: {“pointer”:""}\n domain: “validation”\n keyword: “type”\n found: “object”\n expected: [“array”]\n"}

I really don’t get it. Can any one please help me with this issue.

Sam

Looks like you’re sending an Object instead of an Array? Can you copy the link_click request you’re sending? And are you sending something custom or using the link_click function buildin from Snowplow?

@Koen87 is exactly right - you should be sending in an array of contexts (even if that array only has one element), not a single context object.

Hi Guys,

Thank you for the replies.

I tried with the example of php tracker using custom context:

https://github.com/snowplow/snowplow/wiki/PHP-Tracker#custom-context

So, here is what I pass to the function for track page view:

$tracker->trackPageView(
    "http://www.films.com", 
    "Homepage", 
    NULL,
    array(
        "schema" => "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",
        "data" => array(
            "elementId" => "1234", 
            "targetUrl" => "http://www.google.com"
        )
    )
);

The validation schema is just the same as on github:

{
	"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
	"description": "Schema for a link click event",
	"self": {
		"vendor": "com.snowplowanalytics.snowplow",
		"name": "link_click",
		"format": "jsonschema",
		"version": "1-0-1"
	},

	"type": "object",
	"properties": {
		"elementId": {
			"type": "string"
		},
		"elementClasses": {
			"type": "array",
			"items": {
				"type": "string"
			}
		},
		"elementTarget": {
			"type": "string"
		},
		"targetUrl": {
			"type": "string",
			"minLength": 1
		},
		"elementContent": {
			"type": "string"
		}
	},
	"required": ["targetUrl"],
	"additionalProperties": false
}

The purpose of using the link_click as the custom context is to avoid other factor of failure like miss setting of custom iglu serve.

Please see your opinion?

Thanks!

Sam

Nice, I got it work guys! Thanks for your hints to have multiple context, the document in the php tracker is wrong compare to the one in javascript tracker in https://github.com/snowplow/snowplow/wiki/2-Specific-event-tracking-with-the-Javascript-tracker#custom-contexts

If it is to be able to accept multiple schemas, then the structure should be like this:

$tracker->trackPageView(
    "http://www.films.com", 
    "Homepage", 
    NULL,
    array(
        array(
            "schema" => "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",
            "data" => array(
                "elementId" => "1234", 
                "targetUrl" => "http://www.google.com"
            )
        )
    )
);

And then I got the mini working. Please update the document in PHP tracker custom context section.

Thanks alot!

Sam

Hi Sam - thanks so much for posting back with the fix. We’ll fix the PHP Tracker documentation: https://github.com/snowplow/snowplow/issues/2677