diff --git a/pkg/transform/snowplow_gtmss_preview.go b/pkg/transform/snowplow_gtmss_preview.go index e2556dd4..8c6dfbe8 100644 --- a/pkg/transform/snowplow_gtmss_preview.go +++ b/pkg/transform/snowplow_gtmss_preview.go @@ -77,25 +77,26 @@ func gtmssPreviewTransformation(ctx, property, headerKey string, expiry time.Dur return nil, nil, message, nil } - tstamp, err := parsedEvent.GetValue("collector_tstamp") + headerVal, err := extractHeaderValue(parsedEvent, ctx, property) if err != nil { message.SetError(err) return nil, nil, message, nil } - if collectorTstamp, ok := tstamp.(time.Time); ok { - if time.Now().UTC().After(collectorTstamp.Add(expiry)) { - message.SetError(errors.New("Message has expired")) + if headerVal != nil { + tstamp, err := parsedEvent.GetValue("collector_tstamp") + if err != nil { + message.SetError(err) return nil, nil, message, nil } - } - headerVal, err := extractHeaderValue(parsedEvent, ctx, property) - if err != nil { - message.SetError(err) - return nil, nil, message, nil - } - if headerVal != nil { + if collectorTstamp, ok := tstamp.(time.Time); ok { + if time.Now().UTC().After(collectorTstamp.Add(expiry)) { + message.SetError(errors.New("Message has expired")) + return nil, nil, message, nil + } + } + if message.HTTPHeaders == nil { message.HTTPHeaders = make(map[string]string) } diff --git a/pkg/transform/snowplow_gtmss_preview_test.go b/pkg/transform/snowplow_gtmss_preview_test.go index 02b8c832..5b88a26f 100644 --- a/pkg/transform/snowplow_gtmss_preview_test.go +++ b/pkg/transform/snowplow_gtmss_preview_test.go @@ -244,6 +244,29 @@ func TestGTMSSPreview(t *testing.T) { ExpInterState: nil, Error: errors.New("Message has expired"), }, + { + Scenario: "no_gtmss_no_expire", + Ctx: "contexts_com_google_tag-manager_server-side_preview_mode_1", + Property: "x-gtm-server-preview", + HeaderKey: "x-gtm-server-preview", + Expiry: 1 * time.Hour, + InputMsg: &models.Message{ + Data: spTsvNoGtmss, + PartitionKey: "pk", + }, + InputInterState: nil, + Expected: map[string]*models.Message{ + "success": { + Data: spTsvNoGtmss, + PartitionKey: "pk", + HTTPHeaders: nil, + }, + "filtered": nil, + "failed": nil, + }, + ExpInterState: spTsvNoGtmssParsed, + Error: nil, + }, } for _, tt := range testCases {