Created
March 22, 2012 06:32
-
-
Save yosimox/2156653 to your computer and use it in GitHub Desktop.
サーバーログでイベントトラッキングする用のJSライブラリ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EvTrack | |
constructor: (url)-> | |
@url = url | |
@opt = { | |
category : "" | |
action : "" | |
label : "" | |
value : "" | |
} | |
@optName = { | |
category : "cat" | |
action : "act" | |
label : "lab" | |
value : "val" | |
} | |
begin: (param) -> | |
objBody = document.getElementsByTagName("body").item(0) | |
ele = document.createElement("img") | |
ele.src = @url + "?" + param | |
objBody.appendChild(ele) | |
makeParam: ()-> | |
str = "r=#{Math.round(Math.random() * (new Date).getTime() / 1000)}" | |
str += "&#{@optName['category']}=#{encodeURIComponent(@opt['category'])}" | |
str += "&#{@optName['action']}=#{encodeURIComponent(@opt['action'])}" | |
str += "&#{@optName['label']}=#{encodeURIComponent(@opt['label'])}" | |
if @opt['value'] != "" && @opt["value"]? | |
str += "&#{@optName['value']}=#{encodeURIComponent(@opt['value'])}" | |
return str | |
parseArr : (arr)-> | |
if (arr.length == 3 || arr.length == 4) | |
@opt = { | |
category : arr[0] | |
action : arr[1] | |
label : arr[2] | |
} | |
@opt.value = arr[3] if arr[3]? | |
return @opt | |
track : (arr)-> | |
this.parseArr(arr) if arr? | |
param = this.makeParam() | |
this.begin(param) | |
this.clear() | |
return false | |
clear : ()-> | |
@opt = { | |
category : "" | |
action : "" | |
label : "" | |
value : "" | |
} | |
#ビーコン画像の置いてある場所を指定 | |
url = "b.gif" | |
window._evTrac = new EvTrack(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment