Skip to content

Commit

Permalink
Pixel-based tracking redirects (#553)
Browse files Browse the repository at this point in the history
* Add redirect-based pixel tracking
  • Loading branch information
jakthom authored May 3, 2023
1 parent 92f4f84 commit 4f9eec6
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.16.1
v0.16.2
2 changes: 1 addition & 1 deletion deploy/terraform/aws/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ variable "buz_domain" {
variable "buz_version" {
description = "The version of Buz to run."
type = string
default = "v0.16.1"
default = "v0.16.2"
}

variable "buz_lambda_memory_limit" {
Expand Down
2 changes: 1 addition & 1 deletion deploy/terraform/gcp/cloud_run/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable "buz_domain" {
variable "buz_version" {
description = "The version of Buz to run."
type = string
default = "v0.16.1"
default = "v0.16.2"
}

variable "buz_service_timeout_seconds" {
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ x-dependency:
services:
buz:
container_name: buz
image: ghcr.io/silverton-io/buz:v0.16.1
image: ghcr.io/silverton-io/buz:v0.16.2
volumes:
- type: bind
source: ./buz/quickstart.conf.yml
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/buz.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ const (
BUZ_VALID_EVENTS string = "buz_valid_events"
BUZ_INVALID_EVENTS string = "buz_invalid_events"
BUZ string = "buz"
BUZ_REDIRECT_PARAM string = "z"
)
3 changes: 2 additions & 1 deletion pkg/protocol/pixel/eventBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"

"github.com/gin-gonic/gin"
"github.com/silverton-io/buz/pkg/constants"
"github.com/silverton-io/buz/pkg/envelope"
"github.com/silverton-io/buz/pkg/util"
)
Expand All @@ -19,7 +20,7 @@ const (
)

func buildEvent(c *gin.Context) (envelope.SelfDescribingPayload, error) {
params := util.MapUrlParams(c)
params := util.MapUrlParams(c, constants.BUZ_REDIRECT_PARAM) // Remove reserved redirect param
schemaName := util.GetSchemaNameFromRequest(c, ARBITRARY_PIXEL_SCHEMA)
base64EncodedPayload := params[B64_ENCODED_PAYLOAD_PARAM]
if base64EncodedPayload != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/protocol/pixel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (i *PixelInput) Handler(m manifold.Manifold, conf config.Config, metadata *
c.Header("Retry-After", response.RETRY_AFTER_60)
c.JSON(http.StatusServiceUnavailable, response.ManifoldDistributionError)
} else {
redirectUrl, _ := c.GetQuery(constants.BUZ_REDIRECT_PARAM)
if redirectUrl != "" {
log.Debug().Msg("🟢 redirecting to " + redirectUrl)
c.Redirect(http.StatusFound, redirectUrl)
}
b, _ := base64.StdEncoding.DecodeString(PX)
c.Data(http.StatusOK, "image/png", b)
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/util/mapUrlParams.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand All @@ -12,11 +12,19 @@ import (

// Coerce query params to a map[string]interface{}.
// Only use the first val of each key.
func MapUrlParams(c *gin.Context) map[string]interface{} {
func MapUrlParams(c *gin.Context, excludeParams ...string) map[string]interface{} {
mappedParams := make(map[string]interface{})
params := c.Request.URL.Query()
for k, v := range params {
mappedParams[k] = v[0]
if excludeParams != nil {
for _, excludeParam := range excludeParams {
if k != excludeParam {
mappedParams[k] = v[0]
}
}
} else {
mappedParams[k] = v[0]
}
}
return mappedParams
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/mapUrlParams_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/pprint_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/schema.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand Down
4 changes: 4 additions & 0 deletions pkg/util/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

package util

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/structToMap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/structToMap_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand Down
3 changes: 2 additions & 1 deletion pkg/util/time.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

package util

import "time"

// GetDuration returns the associated duration between two times
func GetDuration(start time.Time, end time.Time) time.Duration {
return end.Sub(start)
}
2 changes: 1 addition & 1 deletion pkg/util/time_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Silverton Data, Inc.
// Copyright (c) 2023 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE

Expand Down

0 comments on commit 4f9eec6

Please sign in to comment.