Skip to content

Commit

Permalink
impression track url
Browse files Browse the repository at this point in the history
  • Loading branch information
wenweihu86 committed Oct 20, 2017
1 parent f134303 commit 87442ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/adhandler/search_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"adserver"
"strings"
"fmt"
"bytes"
"encoding/base64"
)

func SearchHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -99,6 +101,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
MainImageUrl: adCreative.MainImageUrl,
ClickUrl: adCreative.ClickUrl,
}
adInfo.ImpressionTrackUrl = buildImpressionTrackUrl(req, adInfo)
adList := make([]adserver.AdInfo, 0, 1)
adList = append(adList, adInfo)
res.ResCode = 0
Expand All @@ -117,3 +120,17 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
resBytes, _ := json.Marshal(res)
w.Write(resBytes)
}

func buildImpressionTrackUrl(req *adserver.Request, adInfo adserver.AdInfo) string {
var paramBuf bytes.Buffer
paramBuf.WriteString(fmt.Sprintf("slotId=%s", req.SlotId))
paramBuf.WriteString(fmt.Sprintf("ip=%s", req.Ip))
paramBuf.WriteString(fmt.Sprintf("os=%d", req.Os))
paramBuf.WriteString(fmt.Sprintf("unitId=%s", adInfo.UnitId))
paramBuf.WriteString(fmt.Sprintf("creativeId=%s", adInfo.CreativeId))
paramEncoded := base64.StdEncoding.EncodeToString(paramBuf.Bytes())
impressionTrackUrl := fmt.Sprintf("%s?i=%s",
"http://localhost:8001/ad/impression", paramEncoded)
return impressionTrackUrl
}

2 changes: 2 additions & 0 deletions src/adserver/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type AdInfo struct {
Description string
AppPackageName string
ClickUrl string
ImpressionTrackUrl string
ClickTrackUrl string
}

type Response struct {
Expand Down

0 comments on commit 87442ce

Please sign in to comment.