Close

Parsing of /* <![CDATA[ */ scripts

[email protected]
9 years ago
#7607 Quote
Avatar
  • 37
Our customer is trying to add a Google remarking script to their site via the HTML Widgets plugin. We tell them they can add scripts via the HTML Widget -> Tools -> Source Code <> option.  They are using the body_end_html_tag_before zone.  

This is the script Google gave them (google_conversion_id changed) ... Note the /* commented */ CDATA lines in the original:

<!-- Google Code for Remarketing Tag -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 9999999999;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/9999999999/?value=0&amp;guid=ON&amp;script=0"/>
</div>
</noscript>


After saving, the /* commented */ portions get parsed (which breaks the script):

<!-- Google Code for Remarketing Tag -->
<p>
<script>// <![CDATA[
var google_conversion_id = 9999999999;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
// ]]></script>
<script src="//www.googleadservices.com/pagead/conversion.js">// <![CDATA[

// ]]></script>
</p>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/9999999999/?value=0&amp;guid=ON&amp;script=0"/>
</div>
</noscript>


See the following support URL from Google on the topic:

https://support.google.com/tagassistant/answer/2978937?ref_topic=2947092#cdata_comments

Id really like to avoid having to add this to any CSHTML files since a) this puts scripting back in our court as opposed to letting our customers maintain this info themselves, and b) this complicates upgrades.

FWIW we are seeing similar issues on other 3rd-party scripts as well.  Any thoughts on how to handle this?
Boyko
9 years ago
#7627 Quote
Avatar
  • Moderator
  • 1570
[email protected] wrote:
Our customer is trying to add a Google remarking script to their site via the HTML Widgets plugin. We tell them they can add scripts via the HTML Widget -> Tools -> Source Code <> option.  They are using the body_end_html_tag_before zone.  

...

https://support.google.com/tagassistant/answer/2978937?ref_topic=2947092#cdata_comments

Id really like to avoid having to add this to any CSHTML files since a) this puts scripting back in our court as opposed to letting our customers maintain this info themselves, and b) this complicates upgrades.

FWIW we are seeing similar issues on other 3rd-party scripts as well.  Any thoughts on how to handle this?


Hi [email protected],

Everything added into the editor is escaped. That is why you can't add scripts into it.
It is a good idea to use CDATA to add script into the Html editor as otherwise it will not allow you to do so but anything outside the CDATA will be escaped.
Alternatively you can put this script into a file on the server and simply import it.
This way you only need to make sure the file is uploaded on the server after an upgrade (or update) to the site.

Hope this helps!
Regards,
Nop-Templates.com Team
[email protected]
9 years ago
#7659 Quote
Avatar
  • 37
Boyko wrote:

Alternatively you can put this script into a file on the server and simply import it.
This way you only need to make sure the file is uploaded on the server after an upgrade (or update) to the site.


Boyko - Can you elaborate on this.  Obviously I understand putting the script in a file, but what method specifically do you mean when you say to "simply import it."  Are you implying this can be done thru HTML widgets, via altering the CSHTML file, or thru other means.  

Again, my goal here is to allow our customers to maintain these scripts themselves without us needing to get involved.  That was the whole benefit of using HTML Widgets in the first place.

Thanks!
Boyko
9 years ago
#7662 Quote
Avatar
  • Moderator
  • 1570
[email protected] wrote:

Alternatively you can put this script into a file on the server and simply import it.
This way you only need to make sure the file is uploaded on the server after an upgrade (or update) to the site.

Boyko - Can you elaborate on this.  Obviously I understand putting the script in a file, but what method specifically do you mean when you say to "simply import it."  Are you implying this can be done thru HTML widgets, via altering the CSHTML file, or thru other means.  

Again, my goal here is to allow our customers to maintain these scripts themselves without us needing to get involved.  That was the whole benefit of using HTML Widgets in the first place.

Thanks!


Hi [email protected],

My idea was to have the script into a separate file but obviously you don't want this.
The HTML widgets are designed to insert HTML and that is why they are using the Html Editor.
The Html Editor does not allow you to put script in it and it is escaped.
Why don't you try to put the scripts in the Google Analytics plugin? It allows you to place javascript, so it looks like a good place to put your remarketing script.

Thanks
Regards,
Nop-Templates.com Team