Snowbridge: Issues with `spGtmssPreview` Transformation

The spGtmssPreview transformation has been added to our Snowbridge component. I have followed the guidelines to ensure that the events sent from the client include a single global context matching the key found in the GTM preview mode. However, when testing, no events are coming through to the preview mode.

image

Here’s an example body of a post request when the preview context is added:

payload_body
{"schema":"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4","data":[{"e":"ue","eid":"17f1198e-e48f-406a-b9de-055ed11cbc0b","tv":"js-3.17.0","tna":"consumer_web","aid":"167842055006","p":"web","cookie":"1","cs":"UTF-8","lang":"en-GB","res":"1920x1080","cd":"24","dtm":"1725447892514","vp":"738x934","ds":"738x4528","vid":"2","sid":"e13fb0af-fc66-49fe-9788-f6eb3a54a61e","duid":"0a467913-2845-44d7-85a4-fa2fbb63ff22","refr":"https://www.just-eat.co.uk/area/bs30-area/deals?cuisines=lunch%2Csandwiches","url":"https://www.just-eat.co.uk/area/bs30-area/deals?cuisines=lunch%2Csandwiches%2Cburgers","ue_px":"eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy91bnN0cnVjdF9ldmVudC9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6eyJzY2hlbWEiOiJpZ2x1OmpldC5jdXN0LmRpc2NvdmVyeS9kaXNjb3ZlcnlDb21wb25lbnRfdmlldy9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6e319fQ","cx":"eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9jb250ZXh0cy9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6W3sic2NoZW1hIjoiaWdsdTpqZXQvY3hfcGFnZS9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6eyJpZCI6IjU2ZDA2ODRjLWY4MDktNDllYS1iMzU2LWI0YTViMGE1MWNlOSIsIm5hbWUiOiJzZXJ2aWNlIn19LHsic2NoZW1hIjoiaWdsdTpqZXQvY3hfcGxh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YWdlci5zZXJ2ZXItc2lkZS9wcmV2aWV3X21vZGUvanNvbnNjaGVtYS8xLTAtMCIsImRhdGEiOnsieC1ndG0tc2VydmVyLXByZXZpZXciOiJaVzUyTFROOFdIaG1XREJmZVdGemFVOVhRMFprVVRaS2JIaFRkM3d4T1RFNU5EUXdPVGN6WkRkaE1qQXpaakU1TmpNPSJ9fV19","stm":"1725447892515"}]}```

The GTM context is shown in the logs for the events coming from the good stream:

good_stream_logs_context
...{"schema":"iglu:com.google.tag-manager.server-side/preview_mode/jsonschema/1-0-0","data":{"x-gtm-server-preview":"ZW52LTN8WHhmWDBfeWFzaU9XQ0ZkUTZKbHhTd3wxOTE5NDQwOTczZDdhMjAzZjE5NjM="}}
...

Here’s the config.hcl

Summary
source {
  use "kinesis" {
    # Kinesis stream name to read from (required)
    stream_name       = "${env("SNOWBRIDGE_ENV")}-snowplow-analytics-enriched-good"

    # AWS region of Kinesis stream (required)
    region            = "${env("AWS_REGION")}"

    # App name for Snowbridge (required)
    app_name          = "${env("SNOWBRIDGE_APPNAME")}"

    # # Optional ARN to use on source stream (default: "")

    # Timestamp for the kinesis shard iterator to begin processing.

    # Maximum concurrent goroutines (lightweight threads) for message processing (default: 50)
  }
}

transform {
  use "spEnrichedFilter" {
    # keep only page views
    atomic_field = "event_name"

    regex = "^(page_view|screen_view|order_purchase)$"

    filter_action = "keep"
  }
}

transform {
  use "spGtmssPreview" {}
}

transform {
  use "spEnrichedToJson" {}
}

target {
  use "http" {
    url                        = "https://googletagmanagertagging.${env("ZONE")}/com.snowplowanalytics.snowplow/enriched"
    request_timeout_in_seconds = 10
    content_type               = "application/json"

    headers = ""
  }
}

// log level configuration (default: "info")
log_level = "${env("LOG_LEVEL")}"
disable_telemetry = true

This never arrives at the preview mode in GTM though. Checking the logs I can see the same message is delivered to the GTM tagging server: Successfully wrote 1/1 messages

It does work when I send a attach the header in the HTTP target as shown in the following page. This won’t really work as a solution as it requires a new deployment every time the value changes.

I am using Snowbridge version 2.3.0.

Hi Rob!

This part is slightly confusing, apologies - the transformation provides the header, but to attach it, the http target needs:

# Whether to enable setting headers dynamically
    dynamic_headers            = true

So:

target {
  use "http" {
    url                        = "https://googletagmanagertagging.${env("ZONE")}/com.snowplowanalytics.snowplow/enriched"
    request_timeout_in_seconds = 10
    content_type               = "application/json"

    dynamic_headers = true
  }
}

I can see that this is a bit confusing - I’ll see what I can add to the docs to make it clearer.

The original design decision was intended to prevent unrelated custom transformations from breaking things accidentally - but perhaps this is more abundant caution than is necessary.

Hope that helps - shout if you still have problems.

1 Like