<![CDATA[ Preventing MODX from parsing Google Publisher Tags Javascript code ? - My Forums]]> https://forums.modx.com/thread/?thread=104422 <![CDATA[Preventing MODX from parsing Google Publisher Tags Javascript code ?]]> https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561638 Using GPT JS code for responsive tags, for example :
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
  var googletag = googletag || {};
  googletag.cmd = googletag.cmd || [];
</script>

<script>
  googletag.cmd.push(function() {
  var mapping = googletag.sizeMapping().
	addSize([1280, 0], [[728, 90], [468, 60]]). 
	addSize([980, 0], [468, 60]).
	addSize([600, 0], [320, 50]). 
	build();
	
   googletag.defineSlot('/12345678/OC3-lbgc1', [[728, 90], [320, 50], [468, 60]], 'div-gpt-ad-12345678901234-0').
	defineSizeMapping(mapping).
	addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
  });
</script>


I have a problem whenever there is a [[ in the code (ex , [[728, 90], [320, 50], [468, 60]],) since i guess MODX processes it and it is not rendered.

Is there a way to prevent Modx from parsing this JS code ?

I found a first fix using such a snippet :
<?php
$pubid =  (int) $modx->getOption('pubid', $scriptProperties);
$resource = $modx->getObject('modResource',$pubid);
$output= $resource->get('content');

return $modx->regClientStartupScript($output);


when placed in a resource content to get the JS script above the </head> tag.

However when using for instance :
<?php
$pubid =  (int) $modx->getOption('pubid', $scriptProperties);
$resource = $modx->getObject('modResource',$pubid);
$output= $resource->get('content');

return $output;
to use it in a template (pubid being the id# of the JS resource with the appropriate Google JS code) it
doesn't work !
I get
   googletag.defineSlot('/12345678/OC3-lbgc1', , 'div-gpt-ad-12345678901234-0').

instead of
   googletag.defineSlot('/12345678/OC3-lbgc1', [[728, 90], [320, 50], [468, 60]], 'div-gpt-ad-12345678901234-0').

so the Google code is broken.

Any idea ?
Thanks !]]>
justinet Sep 19, 2018, 03:53 PM https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561638
<![CDATA[Re: Preventing MODX from parsing Google Publisher Tags Javascript code ?]]> https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561701 regClientStartupHTMLBlock(). Check out the "See Also" section on that page for other options.

I'm not sure this is relevant for your issue but for the MODX regClient script functions, if your code contains script tags, it will be injected unaltered. If not, MODX will add the script tags itself.]]>
BobRay Sep 22, 2018, 06:04 PM https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561701
<![CDATA[Re: Preventing MODX from parsing Google Publisher Tags Javascript code ?]]> https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561698 Adding a space works with Modx but seems to break the GPT code (not so easy to tell because these are screen dimensions options which are not always used depending upon screen, ad availability, etc)

As i would prefer not to modify anything in the Google code (it's actually their GPT rules) i was looking for solutions on the Modx side.
For instance with
return $modx->regClientStartupScript($output);
(my first a.m. snippet) the JS code is not amended

which is not the case with
 return $output= $resource->get('content');
where the JS code is parsed (used in a chunk in template)

Is there for instance another Modx function behaving like regClientStartupScript ?
Thanks]]>
justinet Sep 22, 2018, 08:36 AM https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561698
<![CDATA[Re: Preventing MODX from parsing Google Publisher Tags Javascript code ?]]> https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561651 CDATA tags.

It should also work to put a space between the leading pair of square brackets:

[ [728, 90]


MODX then won't view them as the start of a MODX tag. You can leave the trailing ones alone.]]>
BobRay Sep 19, 2018, 05:33 PM https://forums.modx.com/thread/104422/preventing-modx-from-parsing-google-publisher-tags-javascript-code#dis-post-561651