Example #1
0
func ViewCounter(ac *wrappers.AppContext, sID string, c web.C, w http.ResponseWriter, r *http.Request) (int, error) {

	adID := r.FormValue("a")
	originIP, _, errIP := net.SplitHostPort(r.RemoteAddr)
	if errIP != nil {
		return http.StatusInternalServerError, errIP
	}
	timeGen, errT := common.FormTime("g", r)
	if errT != nil {
		return http.StatusInternalServerError, errT
	}
	referer := r.Header.Get("referer")

	// log.Println("View ADID", adID)
	// log.Println("View Origin IP", originIP)
	// log.Println("View Gen Time", timeGen)
	// log.Println("View Referer", referer)
	// log.Println("View IDSession", sID)

	//Add to DB
	ac.Data.AdViews.Insert(adID, referer, originIP, timeGen, sID)

	//Send GIF response
	gif, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=")
	w.Header().Set("Content-Type", "image/gif")
	io.WriteString(w, string(gif))

	return 200, nil
}
Example #2
0
func ClickTracking(ac *wrappers.AppContext, sID string, c web.C, w http.ResponseWriter, r *http.Request) (int, error) {

	adID := r.FormValue("a")
	originIP, _, errIP := net.SplitHostPort(r.RemoteAddr)
	if errIP != nil {
		return http.StatusInternalServerError, errIP
	}

	timeGen, errT := common.FormTime("g", r)
	if errT != nil {
		return http.StatusInternalServerError, errT
	}

	destLink := r.FormValue("l")
	tag := r.FormValue("t")
	referer := r.Header.Get("referer")

	conversions.AddCookie(w, adID)

	// log.Println("Link Path: ", r.URL.Path[1:])
	// log.Println("Link Gen Time: ", timeGen)
	// log.Println("Link ADID: ", adID)
	// log.Println("Link Click Through: ", destLink)
	// log.Println("Link Tag: ", tag)
	// log.Println("Link Referer: ", referer)
	// log.Println("Link IDSession", sID)

	ac.Data.AdClickThroughs.Insert(adID, referer, destLink, originIP,
		timeGen, tag, sID)

	http.Redirect(w, r, destLink, http.StatusFound)

	return 302, nil
}
Example #3
0
func Conversions(ac *wrappers.AppContext, c web.C, w http.ResponseWriter, r *http.Request) (int, error) {

	adID, errA := conversions.GetCookie(r)
	if errA != nil {
		return http.StatusOK, errA
	}

	originIP, _, errIP := net.SplitHostPort(r.RemoteAddr)
	if errIP != nil {
		return http.StatusOK, errIP
	}

	timeGen, errT := common.FormTime("g", r)
	if errT != nil {
		return http.StatusOK, errT
	}

	sessionID, errS := session.GetSessionCookie(r)
	if errS != nil {
		return http.StatusOK, errS
	}

	conversionTag := r.FormValue("t")
	//Limit to 64 characters
	if len(conversionTag) > 64 {
		conversionTag = conversionTag[:64]
	}

	referer := r.Header.Get("referer")

	// log.Println("Conversion Origin IP: ", originIP)
	// log.Println("Conversion Referer: ", referer)
	// log.Println("Conversion Gen Time: ", timeGen)
	// log.Println("Conversion adID: ", adID)
	// log.Println("Conversion Conversion Tag: ", conversionTag)
	// log.Println("Conversion Session: ", sessionID)

	//Add to DB
	ac.Data.AdConversions.Insert(adID, referer, originIP, timeGen, conversionTag, sessionID)

	//Send GIF response
	gif, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=")
	w.Header().Set("Content-Type", "image/gif")
	io.WriteString(w, string(gif))

	return 200, nil
}