0

I'm trying to track the contacts by logging them into a DE as soon as they click on a CTA on cloud page. I'm using onclick event and passing the value to a variable and then trying to pass the Javavar variable value to ampscript variable. For some reason am having issues passing java variable to ampscript variable. Can you please suggest a best practice to achieve this.

Here is my code,

<a id="abc" value="clicked" onclick="return check()" href="https://salesforce.stackexchange.com/" class="xyz">Click here</a>

<script runat=server>
Platform.Load("core","1");

function check()
{
 var javavar = document.getElementById("abc");
 Variable.Setvalue("@ampscriptvar",javavar);
}
</script>

Based on AMP Script value I'm inserting the contact information to a data extension using InsertDE function.

How to determine if someone clicked on the CTA?

2 Answers 2

0

You need to remove the @ sign from the variable in your SSJS code. The line should be: Variable.Setvalue("ampscriptvar",javavar); }

You should also make sure the ampscript variable exists prior to setting the value.

0

Your client side click handler will not be able to call the server side function. The SSJS block will run independently when the page is being rendered by the server, and client browsers will not be able to call it.

To make this work, I would setup a second page where every request to it is logged, perhaps with added values passed to the page as parms.

From there you have two options. 1) Use your current method of adding a click handler to instead make an Ajax request to 2nd page.

2) Potentially easier. You could have your link go directly to the second page, and use a redirect to take the user to a destination page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .