I understand that part but how do you alter this script to read the doSomethingElse() ? Meaning have both event.asp?id=1 AND event.asp?id=2. How do you distinguish 1 vs 2 ?
Not 100% sure Iām understanding your question, but Iāll give it a shot. Come back and clarify for me if this doesnāt help.
I would start by making your loadXMLDoc function a little more general. If you make the element ID and the endpoint parameters in your function, you can then pass in your own values when you call the function in order to fetch different resources.
<script>
function loadXMLDoc(elementId, endpoint) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(elementId).innerHTML =
this.responseText;
}
};
xhttp.open("GET", endpoint, true);
xhttp.send();
}
</script>
Then, in your onclick attribute, you can call that function twice passing in the appropriate arguments.
Thank you again for that code which I have in use. I want to track if a user clicks on an embedded video. I donāt see how I can utilize this code for that.
Iām not sure what you mean by ātrack if a user clicks on an embedded video.ā Do you want to listen for a click event on a video and do something when it is clicked?
I just want to be able to log in my database when someone clicks on play on a youtube video that is embedded on my site. I just couldnāt figure out a way to do that and not sure if itās even possible.
I know that you can you Youtube to track views and locations. I am a little confused about the Google analytics.js though.
Does this mean you can send data to my previously discussed event.asp page to do your own tracking? I see in the function onPlayerStateChange(event) it mentions 'send" ā¦ āSome Labelā, etc. Or am I completely misunderstanding that? Thank you.
Honestly, I am not sure if the code you posted will do it or not.
I can tell you that the above code works great for tracking. What I didnāt know if there is a way to take a typical youtube video embed and track if a user has clicked the play button; hence sending that info to the database log which is triggered in the event.asp?id=1 or id=2 code.