Recently, I was creating a module to add google remarketing tag to a webstore. I have prepared google_tag_params for different type of pages (product, category, cart etc.) according to the documentation. Everything went well until the client checked the page with Google Tag Assistant add-on to Chrome. It shows a warning for CDATA section. At first I didn't understand what he is talking about as the parameters were fine and I didn't receive any errors in the console. So I have checked the Google Tag Assistant and to my surprise it acts as follows.

For code:

<script type="text/javascript">
//<![CDATA[
var google_conversion_id = <?php echo $this->getConversionId();?>;
var google_conversion_label = '<?php echo $this->getConversionLabel();?>';
var google_custom_params = window.google_tag_params;
var google_remarketing_only = <?php echo $this->getRemarketingOnlyFlag();?>;
//]]> 
</script>

It shows warning "Missing CDATA comments" and points to the documentation https://support.google.com/tagassistant/answer/2978937?ref_topic=2947092#cdata_comments

But changing this to

<script type="text/javascript">
/*<![CDATA[*/
var google_conversion_id = <?php echo $this->getConversionId();?>;
var google_conversion_label = '<?php echo $this->getConversionLabel();?>';
var google_custom_params = window.google_tag_params;
var google_remarketing_only = <?php echo $this->getRemarketingOnlyFlag();?>;
/*]]> */
</script>

Makes the warning disappear.

So my question is this. Is there any difference between oneline comment and multiline comment in any browser? Is this only google tag assistant weird behaviour that does not recognize those comments?

有帮助吗?

解决方案 2

No, there is no difference. Google Tag Assistent simply doesn't recognize the line-break terminated comments.

其他提示

Some html minifiers may have a problem during minification.

For example

<script type="text/javascript">
//<![CDATA[
    alert("Hello World");
//]]> 
</script>

become

<script type="text/javascript">//<![CDATA[alert("Hello World");//]]></script>

So /*<![CDATA[*/ is just a little bit more safe.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top