【问题标题】:Google ads scripts are decreasing Google page speed index score谷歌广告脚本正在降低谷歌页面速度指数得分
【发布时间】:2022-01-07 15:18:39
【问题描述】:

有没有办法在页面加载后加载谷歌脚本,从而不影响谷歌页面速度指数?

【问题讨论】:

    标签: google-tag-manager google-ads-script


    【解决方案1】:

    此代码对繁重的 javascript 代码设置了超时,如果用户滚动它也会运行,因此内容会显示得更快

    var scrollCounter = false;
    var pageType = typeof signal !== 'undefined' && signal.Content.ArticleId!=null?'article':'notanarticle';
    var cds = /Mobi/.test(navigator.userAgent) && document.body.clientWidth < 737 ? 'Mobile' : /Mobi/.test(navigator.userAgent) && document.body.clientWidth > 767 ? 'Tablet' : 'Desktop';
    if (cds == 'Mobile') {
        //condition for home and section pages
          if(pageType == 'notanarticle') {
           setTimeout(function() {
                if (!scrollCounter) {
                    scrollCounter = true;
                    console.log('timeout');
                    addThirdPartyLibs();
                }
            }, 4000);   
         }//end of condition
        var activityEvents = [
            'keydown', 'touchstart', 'scroll'
        ];
        activityEvents.forEach(function(eventName) {
            document.addEventListener(eventName, function(e) {
                if (!scrollCounter) {
                    scrollCounter = true;
                    console.log(window.scrollY);
                    addThirdPartyLibs();
                }
            }, true);
        });
    } else {
        addThirdPartyLibs();
    }
    
    function addThirdPartyLibs() {
        loadGPTJs();
    
    }
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多