Exemple #1
0
func RenderTrackingJs(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseFiles(webtrack.GetResource("templates", "track.js"))
	webtrack.CheckErrorPanic(err)

	w.Header().Set("Content-type", "application/javascript")

	user_key := mux.Vars(r)["userKey"]
	cb_url, err := webtrack.BootstrapURL("track_callback",
		"userKey", user_key,
		"origTrackId", "",
	)

	webtrack.CheckErrorPanic(err)

	data := TrackJsData{
		Key:      user_key,
		Callback: cb_url,
	}

	var maxjs bytes.Buffer
	tmpl.Execute(&maxjs, data)

	minified := webtrack.Minify(maxjs.String(), "js")
	w.Write([]byte(minified))
}
func SamplePage(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-type", "text/html")

	tmpl, err := template.ParseFiles(webtrack.GetResource("templates", "samplepage.html"))
	webtrack.CheckErrorPanic(err)

	script_url, err := webtrack.Router.Get("trackjs").URL("userKey", "XXXXXXXXXX")
	webtrack.CheckErrorPanic(err)

	err = tmpl.Execute(w, script_url)
	webtrack.CheckErrorPanic(err)
}