Executing a script when clicking
My question:
Can you enter in Web Designer a script that will be executed only when a specific button is clicked.
Purpose:
I have some download buttons and I like to known how many times they are used to download the related file.
It must be possible with a litte script that sends the information to Google Analytics. Google analytics is already included in my website.
That's what I would try to do.
Script:
_gaq.push([‘_trackEvent’, ‘button’, ‘clicked’]);
If someone has another idee to get the same result please let me known.
Thanks
Frank
1 Attachment(s)
Re: Executing a script when clicking
Not familiar with google analytics but the basic concept of executing code at a button click is to add a link starting with javascript: and then following the code. I'd recomment to create a separate function in the page haed code section.
See example that defines two download buttons that worked fine for me, but did only quick testing in Firefox, Chrome and IE9.
Re: Executing a script when clicking
RE: Siran
I'm not so familar with Javascript but after looking at your Xara file, I suppose "javascript:cust_dwnld(1); " is the name of your javascript???
If so could explain where I have to store the javascript and perhaps send me an example of such a script.
Thanks
1 Attachment(s)
Re: Executing a script when clicking
The example code looks like this:
Code:
<script>
function cust_dwnld(n){
var f=["test.pdf","test.docx"];// put the file names of your attachments here and reference them in the button link (numbering starts at 0)
setTimeout(function(){window.open("index_htm_files/"+f[n],"_blank")},100);
alert("Put the code you want to be executed before the download here.");
}
</script>
It is placed at the HTML code (head) of the page (see attached screenshot) in the example, but it can also be placed in a placeholder or in an attached .js file (in the later case the <script> and </script> tags have to be removed).
To add your own code you have to replace the line "alert(..." but I really don't know what you have to place there for the analytic part.
Re: Executing a script when clicking
Thanks Siran, I will try....
Keep you informed.
Frank