Yes, you can use the Beam code in whatever way you see fit. We have designed the Beam code block to accept variables from most scripting languages used on the net today.
For detailed imnformation download our Beam Integration Guide (812KB PDF)
Build the message string outside the javascript codeblock and then echo out the string inside the codeblock - its cleaner and conceptually easier. (Note: all beam variables should be separated by a <br /> AND a newline - view HTML source to confirm).
For sites that have multiple Beams on one page, we have a version of the code block that will reduce the loading time. Below is an example of what this version of the Beam code looks like: