x This domain is for sale. If you intrested, Please contact : webspeckle@gmail.com

Remove google ads from blogger post preview page

Today i got a warning from Google Adsense "There are unauthorized sites that have displayed ads using your AdSense publisher ID within the last week. Please click here..." etc.

I have added all my websites in my adsense authorization page & currently site authorization is active.

In the adsense pageview page, finally i got the url like
https://4492560067822442951_160e48051667999.blogspot.com

'4492560067822442951_160e48051667999' is equalant of my blogger subdomain.i.e
https://4492560067822442951_160e48051667999.blogspot.com = example.blogspot.com

I have a blogger blog with a custom domain. Before publish the post i click on the preview button, it open new tab & show the post preview.

The preview url is like this "https://4492560067822442951_160e48051667999.blogspot.com/b/post-preview?token=3f6aj1fsdfwBAAA.OWl1PrgJZ9iqxEsdfstTU1BW_o8AyE74KVOyWmRglY4gv4FQY_1NyNWdqorJqaSEDaIKvsw7BhLgz2JpAJc7f23_Tw.T3lperu4WH_zIQFxVgfEpA&postId=60302242414450751984379&type=POST"

I think this is the reason for adsense warning.

I had tried to add this domain 4492560067822442951_160e1667999.blogspot.com in adsense authorization page. But invalid url error occured.

How can i solve this problem?
Please take your blogger backup before doing this step.

Solution:

Check if your url contain 'post-preview', the just remove all the google adsense code by using JavaScript or JQuery

Add a div as a wrapper for Google ad code
Eg:
<div class='GoogleAdsWrapper'>
<!-- Add your adsense code here -->
</div>
1) By using JQuery
Add JQuery API. If already added in your blogger ignore it
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Find '$( document ).ready(function() '. If it is found, then add the below lines into it
var CurrentURL = window.location.href;
if(CurrentURL.search(/.blogspot./i) >= 0 && CurrentURL.search(/post-preview/i) >= 0)
{
    $(".adsbygoogle").closest(".GoogleAdsWrapper").remove();
}
If it is not found add the below lines just before '</head>' tag.
$( document ).ready(function()
{
    var CurrentURL = window.location.href;
    if(CurrentURL.search(/.blogspot./i) >= 0 && CurrentURL.search(/post-preview/i) >= 0)
    {
        $(".adsbygoogle").closest(".GoogleAdsWrapper").remove();
    }
});
2) By using JavaScript
Add the below lines just before '</head>' tag.
var child = document.getElementsByClassName("adsbygoogle");
var Parent = child.parentNode;
while (Parent.hasChildNodes())
{
    Parent.removeChild(Parent.firstChild);
}
Done! 

No comments:

Post a Comment