Sort of related to my previous post about member tracking. If I have an HTML element in my post and someone clicks it, is there anyway to know who clicked it. Is there anyway to embed some piece of that user information in the request to the link?
The answer is pretty similar to the your last one.
No native way of doing that, but in the HTML card you can do lots of Javascript magic.
I’d call the /members/api/member/
, see if it returns a user (meaning, somebody is logged in). If yes, put the user information into an object that you can then extend a link with.
Without having tested it, something like this (won’t work out of the box – just more like a demonstration of my thoughts):
<script>
document.addEventListener("DOMContentLoaded", async () => {
// Function to fetch user data
async function fetchUserData() {
try {
const response = await fetch('/members/api/member/');
return await response.json();
} catch (error) {
console.error('Error fetching user data:', error);
return;
}
}
// Function to update the link with user information
async function updateLink() {
const userData = await fetchUserData();
const linkElement = document.getElementById('customised-link');
linkElement.href = `http://example.com/some/request?userId=${userData.userId}`;
}
await updateUserLink();
});
</script>
<a href="#" id="customised-link">Click me</a>
1 Like