Example of using script in campaign attribution enrichment

Hi Snowplowers,

I am working on the campaign attribution enrichment. And I have some special requirements that sometimes all the marketing information is written in “cmm” field, and I need to first split the “cmm” tag if it exists and parse the first one for mkp_medium, the second one for mkp-source… . If it doesn’t exist then try to parse “utm” tag as usual. I just followed this instruction (Add support for non-GA campaign attribution: phase 2 · Issue #436 · snowplow/snowplow · GitHub) and modified my configs as below, but failed. I am wondering whether you have any example of how to use “script” in campaign_attribution.json.

	"schema": "iglu:com.snowplowanalytics.snowplow/campaign_attribution/jsonschema/1-0-1",

	"data": {

		"name": "campaign_attribution",
		"vendor": "com.snowplowanalytics.snowplow",
		"enabled": true,
		"parameters": {
			"mapping": "script",
			"fields": {
				"mktMedium": [cmm.split('|')[0], utm_medium],
                "mktSource": [cmm.split('|')[1], utm_source],
                "mktTerm": [cmm.split('|')[3], utm_term],
                "mktContent": [utm_content],
                "mktCampaign": [cmm.split('|')[2], utm_campaign]


Below is the error log.

[pool-1-thread-1] ERROR com.snowplowanalytics.snowplow.enrich.common.fs2.Run - CLI arguments valid but some of the configuration is not correct. Error: Cannot parse JSON in /snowplow/config/enrichments/campaign_attribution.json: expected json value got 'cmm...' (line 10, column 23)

Hi @phxtorise the linked Github issue was never actioned - it got migrated out of the mono-repo to here (Common: add support for non-GA campaign attribution: phase 2 · Issue #197 · snowplow/enrich · GitHub) but as you can see it is still open.

It would help if you can comment on that issue with your use-case. As it stands however there is no support for what you are trying to do here in the enrichment directly from what I can tell.

Is it possible for you to intercept and “fix” these event before they hit the Snowplow pipeline at all?

@phxtorise This is not the same, but a similar case where three parameters are passed in as a single value in a querystring kv pair, and need to be split up. It uses the JavaScript enrichment to do it. You might find some inspiration in it:


@dilyan Thanks for your solutions! I have several follow-up questions.

  1. I found in the schema of campaign_attribution (image below), there are two mapping methods, one is “static” which is what we commonly use, and another is “script”, what is its use case?
  2. If we both use JavaScript enrichment and Campaign Attribution enrichment, and if they will populate the same field like mkt_source, which one will be processed first? i.e. if one field has already been populated, will another enrichment overwrite the field?


I think the use case was intended for the kind of dynamic / scripted mapping that you want to achieve but as far as know this didn’t make it into the codebase.

Javascript should get executed after the campaign enrichment. The Javascript enrichment can overwrite these existing fields - but you can check for null / empty strings in your script and treat accordingly.


@mike Thanks for your response. But I am still confused about how we can use Javascript enrichment to overwrite these existing fields, like mkt_* columns. Seems like we need to assign a schema for the output in JavaScript enrichment, but I cannot find mkt_* columns’ schema. Could you give me more clues?