• Resolved robertosanchezwp

    (@robertosanchezwp)


    there is something strange on my amp-analytics modules, inside <script type=’application/json’>:

    this is a json inside a amp-analytics node on my site, but between cp1 and cp2, must be an ampersand and shows the unicode character instead. In noamp mode, it shows the & normally

    {“requests”:{“custom_params”:”cp1=test\u0026cp2=test”},”vars”:{“env”:”-preproduction”},”triggers”:{“trackConsent”:{“on”:”visible”,”request”:”impression”}}}

    i tried to convert the string cp1=test\u0026cp2=test to UTF-8, use the html_entity_decode but allways shows de \u0026 instead of &

    thank you in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @robertosanchezwp

    Thank you for reporting this, I was able to reproduce this at my end, and I have created a Github issue in the AMP toolbox for PHP.

    Hopefully, it will get fixed in the next release

    Plugin Author Weston Ruter

    (@westonruter)

    I don’t think this is a problem. See https://github.com/ampproject/amp-toolbox-php/issues/529#issuecomment-1212370988

    • This reply was modified 2 years, 3 months ago by Weston Ruter.
    • This reply was modified 2 years, 3 months ago by Weston Ruter.
    • This reply was modified 2 years, 3 months ago by Weston Ruter.
    Thread Starter robertosanchezwp

    (@robertosanchezwp)

    hello @westonruter yes, a /u0026 when the HTML is printed ends up as & but the amp-analytics module i think it′s before that and i need the same codificaction on amp and noamp pages, so the JSON remains the same way.

    with add_filter( 'amp_enable_optimizer', '__return_false' ) the problem dissapears but i think I’m deactivating some good features too…

    Plugin Author Weston Ruter

    (@westonruter)

    Why does it need to be the same as AMP and non-AMP pages? It should be parsed the same anyway. Have you verified that it is causing a problem?

    As opposed to disabling the entire optimizer, you can also just disable the JSON transformer. This should do it:

    add_filter( 'amp_optimizer_config', static function ( $config ) {
    	$config[ \AmpProject\Optimizer\Transformer\MinifyHtml::class ][ \AmpProject\Optimizer\Configuration\MinifyHtmlConfiguration::MINIFY_JSON ] = false;
    	return $config;
    } );
    Plugin Support Milind More

    (@milindmore22)

    @robertosanchezwp We hope our suggestion is helpful, I’ll mark this as resolved Open a new support topic if you face further issues, also feel free to leave a plugin review, we would love to hear your feedback.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ampersand converted to unicode character on json’ is closed to new replies.