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.
[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)
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.
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?
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?
It doesn’t look like it’s documented much (as it’s supported but not recommended) but if you want to overwrite an existing enriched field you can use something like event.setApp_id("abc") equivalent for your marketing fields.
The suggested way is still to add an additional context (and then you can blend this in your data model). The schema for the existing mkt_* fields (which are part of the atomic definition) can be found here.