Reputation: 53
I use this inside my jsonp file for arrows: "arrows": { "right": { "top": 200, "right": 0, "width": 60, "height": 120 }, "left": { "top": 0, "left": 0, "width": 0, "height": 0 } } }
Does anyone know how to add Google tracking on click to each arrow?
This is regular tracking code: onClick="_gaq.push(['_trackEvent', 'mypagename', 'click', 'arrow'])
Appreciate any help.
Upvotes: 0
Views: 79
Reputation: 4439
I don't know what you mean by "add Google tracking on click to each arrow". Your data is just data, and not arrows. It's possible your client-side javascript uses the data to display something that's clickable, but that's all a matter of client-side javascript and has nothing to do with JSONP.
It is however technically possible to have the JSONP response itself trigger Google tracking code. It's important to remember that JSONP is basically just a piece of javascript that promises to call a specified callback function with some data. But nothing is stopping you from executing some javascript before that. Instead of the usual JSONP response:
callback({"arrows": { "right": { "top": 200, "right": 0, "width": 60, "height": 120 }, "left": { "top": 0, "left": 0, "width": 0, "height": 0 }}}});
You could do something like:
_gaq.push(['_trackEvent', 'mypagename', 'click', 'arrow']);
callback({"arrows": { "right": { "top": 200, "right": 0, "width": 60, "height": 120 }, "left": { "top": 0, "left": 0, "width": 0, "height": 0 }}}});
That is a Google tracking call inside a JSONP response. But I get the impression you don't actually want it inside the JSONP, you probably want it in your user interface. So put it there.
If you're using jQuery, just do
element.click(function() {_gaq.push(['_trackEvent', 'mypagename', 'click', 'arrow'])});
Upvotes: 1