Skip navigation

Tag Archives: javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
$(document).ready(function(){
    $('a').each(function(){
        var link = $(this)[0].href;

        var pdfFiles = /\.(pdf)$/i;
        var imgFiles = /\.(jpg|gif|png)$/i;
        var allFiles = /\.(pdf|doc*|xls*|ppt*|jpg|gif|png|zip|mp3|mp4|mov)$/i;
        var action = '';
        var _onclick = new String($(this).attr('onclick'));

        //remove onclick pagetrack event from links

        if(_onclick.indexOf('pageTracker') != -1)
        {
            $(this).removeAttr('onclick');
        }

        //check to make sure link is not external

        if ((!link.match(/^https?\:/i)) || (link.match(document.domain)))
        {
            //if link leads to a download, we listen to the click event of that link

            //All Files event is guranteed to be tracked at this point

            if(link.match(allFiles))
            {
                $(this).click(function() {
                    action = 'Link Click Capture';

                    //it's a pdf file

                    if(link.match(pdfFiles))
                    {
                        trackIt('PDF Downloads', action, link, 1);
                    }

                    //catch all event

                    trackIt('All Files', action, link, 1);
                });
            }
        }
    });
});
function trackIt(category, action, link, opt)
{
	//sync tracking

   //pageTracker._trackEvent(category, action, link, 1);


	//async

    _gaq.push(['_trackEvent', category, action, link]);
}
1
javascript:void((function(){j=document.createElement("SCRIPT");j.src="http://code.jquery.com/jquery-latest.pack.js";document.getElementsByTagName("HEAD")[0].appendChild(j);})())

you put this in your address bar and hit enter. Bookmarking it would help a lot also.

of course, i didnt write it. I also forgot where i found it too.