简体   繁体   中英

Display ads to search engine visitor only on blogger

I'm using the below code for displaying ads on Blogger but only for search engine/social media visitors.

But the code is not working as the ads are not showing.

What's wrong with this code?

Does anyone have code that only shows things for search engine/social media visitors to a Blogger site?

<script type="text/javascript">
    if (document.referrer.match(/facebook|yahoo|bing|google/)) {

        google_ad_client = "xx-xx-xxxxxxxxxxxxxxxxxx";
        /* xxxxxxxx xxxxxx xxx xxx xxx xx xxxxxx */
        google_ad_slot = "xxxxxxxxxxxxxx";
        google_ad_width = xxx;
        google_ad_height = xxx;

        var script = document.createElement("script");
        script.setAttribute("src", src);
        document.getElementsByTagName("head")[0].appendChild(script);
    } else {
        // Show something to visitors not referred by a search engine
    }
</script>

document.referrer is a URL.That means your regexp( /facebook|yahoo|bing|google/ ) cannot match something like " www.google.com ".

Maybe you should use regexp like /.*google\\.com.*/ ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM