'How to print javascript variables and show them in console?

I'm trying to implement google ads conversion on my website and as per the google team, I added the tags they gave yet the conversion is not showing up properly.

After getting in touch with one of the team members, he told me to correct the code:

So far My code:

  • I m passing an email value through the URL to the 'Thank-you' page.
  • I m echoing the value inside a hidden input tag and calling it back using ID in javascript
  • I can get the value from the input and print it in the console.
<input type="hidden" id="email_for_ads" value="[email protected]">
<script>
  var email_for_ads = $("#email_for_ads").val();
  var enhanced_conversion_data = {
    "email": email_for_ads
  };
    console.log(email_for_ads);
</script>

I can see the email id in the console, and I'm sure the value is being fetched.

But he said it should be like below upon inspect :

<input type="hidden" id="email_for_ads" value="[email protected]">

<script>
  var email_for_ads = $("#email_for_ads").val();
  var enhanced_conversion_data = {
    "email": "[email protected]"
  };
    console.log("[email protected]");
</script>

I even tried the below code too

var baseUrl = (window.location).href; // You can also use document.URL
  var email_for_ads = baseUrl.substring(baseUrl.lastIndexOf('=') + 1);
  //var email_for_ads = $("#email_for_ads").val();
  var enhanced_conversion_data = {
    "email": email_for_ads
  };
    console.log(email_for_ads);

yet the same output. I can see the value in the console but on inspect. But he insists that it is that way and could be able to see the email value directly in inspecting itself.

Can someone understand, whether this is possible, if so, how can i do it.



Solution 1:[1]

You may need a server-side rendering technology to generate your email value into your HTML and scripts.
You can consider starting a service in nodejs, get the email value in the request,and in the response?return the email with your html and scripts.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zyp