VajdaShark Posted October 10, 2014 Share Posted October 10, 2014 (edited) Hi all, this issue is related to javascript compression and moving the javascript to the end: I cannot track conversion via Adwords, because "Error: No HTTP response detected". When I check the source code, I see that tracking code is displaced and divided into multiple pieces. Furthermore, when I disable moving the javacsript to the end, the whole javascript on the page does not load :/ Any help? I am ready to send all the necessary data you will need. SOLVED: By adding the code: {if isset($js_defer) && !$js_defer && isset($js_files) && isset($js_def)} {$js_def} {foreach from=$js_files item=js_uri} <script type="text/javascript" src="{$js_uri|escape:'html':'UTF-8'}"></script> {/foreach}{/if} To the header.tpl and by disabling moving the javascript to the end. Thanks to El Patron. Edited October 10, 2014 by VajdaShark (see edit history) Link to comment Share on other sites More sharing options...
corint1 Posted December 18, 2014 Share Posted December 18, 2014 (edited) where insert this code ? before or after </head> if can you attach your header .tpl or explain more. I use 1.6.0.6. and how disabling moving the javascript to the end. what line must remove or comment? thank you Edited December 18, 2014 by corint1 (see edit history) Link to comment Share on other sites More sharing options...
Alexgaw Posted December 24, 2014 Share Posted December 24, 2014 I also like to know the solution thanks. Link to comment Share on other sites More sharing options...
fatyas Posted January 23, 2015 Share Posted January 23, 2015 Did anyone find a solution for this? I have tried adding the solution proposed by VajdaShark in header.tpl (just before the {$HOOK_HEADER}) but it is till not working. The tag assistant still displays: No HTTP response detected Any Help would be appreciated!!! Link to comment Share on other sites More sharing options...
sachacohenfr Posted April 5, 2015 Share Posted April 5, 2015 I have the same problem, someone have solution ? 1 Link to comment Share on other sites More sharing options...
fransjaeger Posted April 22, 2015 Share Posted April 22, 2015 Mee too Link to comment Share on other sites More sharing options...
sachacohenfr Posted April 22, 2015 Share Posted April 22, 2015 This may help you : https://gist.github.com/prestarocket/1ca849e576fb439183e3 After override the class Media with this code, you just have to write your tracking code with the data-keepinline attribute : <script type="text/javascript" data-keepinline="true"></script> 2 Link to comment Share on other sites More sharing options...
fransjaeger Posted April 22, 2015 Share Posted April 22, 2015 Thank You This may help you : https://gist.github.com/prestarocket/1ca849e576fb439183e3 After override the class Media with this code, you just have to write your tracking code with the data-keepinline attribute : <script type="text/javascript" data-keepinline="true"></script> Thank You I have simplifyed it a bit Class Media extends MediaCore { public static function deferScript($matches) { if (!is_array($matches)) return false; $inline = ''; if (isset($matches[0])) $original = trim($matches[0]); if (isset($matches[1])) $inline = trim($matches[1]); // prestarocket /* This is an inline script, add its content to inline scripts stack then remove it from content */ if (!empty($inline) && preg_match('/<\s*script(?!.*data-keepinline)[^>]*>/ims', $original) !== 0 && Media::$inline_script[] = $inline) return ''; //end prestarocket /* This is an external script, if it already belongs to js_files then remove it from content */ return parent::deferScript($matches); } } But I still have Issue, even though i added Media file and added data-keepinline="true" and deleted class index file and refreshed cache. Link to comment Share on other sites More sharing options...
fransjaeger Posted April 22, 2015 Share Posted April 22, 2015 I been thinking about some way to add something to my OrderConfirmationController.php, that will turn off PS_JS_DEFER, but i cant find any ways Link to comment Share on other sites More sharing options...
fransjaeger Posted April 22, 2015 Share Posted April 22, 2015 This may help you : https://gist.github.com/prestarocket/1ca849e576fb439183e3 After override the class Media with this code, you just have to write your tracking code with the data-keepinline attribute : <script type="text/javascript" data-keepinline="true"></script> My bad. It works Thanks alot I used: Link to comment Share on other sites More sharing options...
leozao Posted June 12, 2015 Share Posted June 12, 2015 I don't understand, you have replaced everything which is by default in Media.php with that small code and there are not damages in some other places?... Link to comment Share on other sites More sharing options...
fransjaeger Posted August 22, 2015 Share Posted August 22, 2015 (edited) I don't understand, you have replaced everything which is by default in Media.php with that small code and there are not damages in some other places?... its called to override and you do it by creating the same file in the override folder (read about it in the docs) - and actually as you can see Im "extending" in a way so that if my scrpt dont do anything, it will just do as the parent (default) function normally do. Edited August 22, 2015 by fransjaeger (see edit history) Link to comment Share on other sites More sharing options...
fransjaeger Posted August 22, 2015 Share Posted August 22, 2015 Hi again this is how i do it, and this works with minifying JS and HTML and Moving JS/CSS to bottom. Im showing the scripts inline and not moving them or changing them, if i just do the data-keepinline="true" trick override/classes/Media.php Class Media extends MediaCore { public static function deferScript($matches) { if (!is_array($matches)) return false; $inline = ''; if (isset($matches[0])) $original = trim($matches[0]); if (isset($matches[1])) $inline = trim($matches[1]); // prestarocket // This is an inline script, add its content to inline scripts stack then remove it from content if (!empty($inline) && preg_match('/<\s*script(?!.*data-keepinline)[^>]*>/ims', $original) !== 0 && Media::$inline_script[] = $inline) return ''; //end prestarocket // This is an external script, if it already belongs to js_files then remove it from content preg_match('/src\s*=\s*["\']?([^"\']*)[^>]/ims', $original, $results); if (array_key_exists(1, $results)) { if (substr($results[1], 0, 2) == '//') { $protocol_link = Tools::getCurrentUrlProtocolPrefix(); $results[1] = $protocol_link.ltrim($results[1], '/'); } if (in_array($results[1], Context::getContext()->controller->js_files) || in_array($results[1], Media::$inline_script_src)) return ''; } // return original string because no match was found return $original; } public static function packJSinHTML($html_content) { if (strlen($html_content) > 0) { // This is an inline script, add its content to inline scripts stack then remove it from content if (preg_match('/<\s*script(?!.*data-keepinline)[^>]*>/ims', $html_content) == 0) return str_replace(array('>/* */', '/* */</script>'), array('>/* <![CDATA[ */', ' /* ]]> */</script>'), $html_content); return parent::packJSinHTML($html_content); } return false; } } Part of my footer.tpl <script data-keepinline="true" type='text/javascript'> var google_tag_params = { ecomm_prodid: '{$product->id}{if isset($combinations) && $combinations}-1{/if}-{$lang_iso}', ecomm_pagetype: 'product', ecomm_totalvalue: '{$product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision)|floatval}' } ; </script> to make ganalytics module work correctly I had to also edit that fil in modules/ganalytics/ganalytics.php private function _getGoogleAnalyticsTag($back_office = false) { // added a line -> ga(\'require\', \'displayfeatures\'); // added data-keepinline="true" /* original code return ' <script type="text/javascript"> (window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\'); (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\'); ga(\'create\', \''.Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')).'\', \'auto\'); ga(\'require\', \'displayfeatures\'); ga(\'require\', \'ec\'); '.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '').' </script>'; */ return ' <script type="text/javascript" data-keepinline="true"> (window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\'); (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\'); ga(\'create\', \''.Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')).'\', \'auto\'); ga(\'require\', \'ec\'); '.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '').' </script>'; } Link to comment Share on other sites More sharing options...
Enrique Gómez Posted April 25, 2016 Share Posted April 25, 2016 This may help you : https://gist.github.com/prestarocket/1ca849e576fb439183e3 After override the class Media with this code, you just have to write your tracking code with the data-keepinline attribute : <script type="text/javascript" data-keepinline="true"></script> Thanks it works. Link to comment Share on other sites More sharing options...
Recommended Posts