This function can help you to find the position of the clicked element listening the event and detecting the position via the jQuery function of position(), all of this adding a listener, this code needs to be implemented on the page or inside a custom HTML tag
$("a").click(function(event) {
var loc = $(this).position();
dataLayer = window.dataLayer || [];
dataLayer.push({ 'event' : 'click_element' , 'posy' : loc.top , 'posx': loc.left });
});
Also must be a clean way to do this inside a var, but it's a little more complicated to create that function.
Greetings
------------- Old Answer -----------------
What type of event are you talking about? this is a click? or is a event lauched by a Javascript? For example for a function on your head what you determine as X and Y?
Maybe determine what type of events can guide better the answer, this case, for example, you can see an example of clickEvent Position.
This function can be helpful, this track your mouse location and pushes the information to the dataLayer.
var posX;
var posY;
document.onmousemove = function(e){
posX= e.pageX;
posY= e.pageY;
};
function mouseLocation(){
if(typeof window.dataLayer === 'undefined'){ window.dataLayer = window.dataLayer || [] };
dataLayer.push({ 'event' : 'mouseLocation', 'PosX' : posX, 'PosY' : posY});
};
// paste this on the head or inside an HTML tag.
mouseLocation(); //Use this function on the onClick on the object to be track
You can try to add this as a variable adding a return on the function if you want to be used with a click listener. Remember that the location depends on the aspect ratio and resolution, so the button can be on the same place, but the X and Y location might not be the same.