Code Force Click Popup quảng cáo trên Blogger

Force Click Popup giúp các bạn tăng thêm thu nhập bắt người dùng click vào quảng cáo để bỏ qua quảng cáo và tiếp tục xem trang web hay blog của bạn.

Trong bài viết này mình sẽ chia sẻ cho các bạn đoạn code JavaScript Force Click Popup quảng cáo cho Blogger. Nó có thể giúp các bạn tăng thêm thu nhập từ việc bắt người dùng click vào quảng cáo của Google được hiển thị trong popup để có thể tiếp tục xem trang hay đọc bài viết.

Tạo khung chứa code có nút copy và download trên Blogger
Tạo khung chứa code có nút copy và download trên Blogger

Code Force Click Popup quảng cáo này sẽ lấy random id quảng cáo của bạn để tránh bị giới hạn quảng cáo, các bạn cũng có thể cài đặt cookie để quảng cáo có thể hiển thị lại sau 1 thời gian mà người dùng đã click cái này để tránh bị spam click cũng như giảm khả năng bị Google Adsense ban.

Mình cũng không khuyến khích các bạn dùng code này vì có thể nó làm khó chịu cho người dùng và một ngày nào đó có thể bị Google Adsense ban.

Cách thực hiện

Cách thực hiện các bạn không cần biết nhiều về những kiến thức HTML, CSS hoặc JS vì mình đã code sẵn cho các bạn. Các bạn cần làm theo chính xác các bước hướng dẫn của mình là được.

Bước 1: Trước hết Đăng nhập vào Trang tổng quan Blogger.

Bước 2: Trên bảng điều khiển Blogger, nhấp vào Chủ đề.

Bước 3: Nhấp vào biểu tượng mũi tên xuống bên cạnh nút 'TÙY CHỈNH'.

Bước 4: Nhấp vào Chỉnh sửa HTML, bạn sẽ được chuyển đến trang chỉnh sửa.

Bước 5: Bây giờ tìm kiếm mã </body> và dán các mã JS sau ngay trên vào nó.

<script>/*<![CDATA[*/
  ! function (c) {
    const l = {
      get: e => (e = document['cookie']['match'](new RegExp('(?:^|; )' + e.replace(/([.$?*|{}()[\]\\/+^])/g, "$1") + '=([^;]*)'))) ? decodeURIComponent(e[1]) : void 0,
      set: (e, t, n = {}) => {
        (n = {
          path: "/",
          ...n
        })['expires'] instanceof Date && (n['expires'] = n['expires']['toUTCString']());
        let i = unescape(encodeURIComponent(e)) + "=" + unescape(encodeURIComponent(t));
        for (var a in n) {
          i += "; " + a;
          var r = n[a];
          !0 !== r && (i += "=" + r)
        }
        document['cookie'] = i
      },
      rem: e => {
        const t = {};
        t['max-age'] = -1, l.set(e, "", t)
      }
    };
    function e() {
      return null !== document['getElementById']('nldblog-ad')
    }
    function r(e) {
      return 'function' == typeof e
    }
    function n(a) {
      let s = document['createElement']('div');
      s.id = 'nldblog-ad', s.classList['add']('fcAd'), s.innerHTML = "<div class='fcFx'><button class='fcBt hidden'><svg viewBox='0 0 24 24'><path d='M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z'/></svg><span>" + c.message + "</span></button><div class='fcCn'><ins class='adsbygoogle' data-ad-client='ca-pub-" + c['publisherID'] + "' data-ad-format='auto' data-ad-slot='" + c['adUnits'][Math['floor'](Math['random']() * c['adUnits']['length'])] + "' data-full-width-responsive='false' style='display:block'></ins></div></div>", document['body'].appendChild(s);
      let d = [];
      function u(e, t) {
        const n = {};
        n['shown'] = !1, n.clicked = null, n['error'] = t || null, 0 === d['length'] && (e ? (l['set'](c['cookie'], 1, {
          secure: !0,
          "max-age": c['maxage']
        }), setTimeout(function () {
          const e = {};
          e['shown'] = !0, e['clicked'] = !0, s['remove'](), r(a) && a(e)
        }, 2e3)) : (s['remove'](), r(a) && a(n)), d['push'](1))
      }
      try {
        (adsbygoogle = window['adsbygoogle'] || [])['push']({})
      } catch (e) {
        u(!1, e)
      }
      let f = s['querySelector'](".fcCn ins.adsbygoogle");
      null !== f && f['addEventListener']('click', function (e) {
        u(!0)
      });
      let p = setInterval(() => {
        var t = s['querySelector']('.fcCn ins.adsbygoogle iframe'),
            e = f['getAttribute']('data-ad-status');
        const o = {};
        o['shown'] = !1, o['clicked'] = null, "unfilled" === e ? (clearInterval(p), r(a) && a(o)) : 'filled' === e && null !== t && (clearInterval(p), s['querySelector'](".fcBt")['classList']['remove']('hidden'), window['addEventListener']('blur', function (e) {
          document['activeElement'] === t && u(!0)
        }))
      }, 100);
      setTimeout(function () {
        ('done' !== f['getAttribute']('data-adsbygoogle-status') || 'done' === f['getAttribute']('data-adsbygoogle-status') && 'filled' !== f['getAttribute']('data-ad-status')) && u(!1)
      }, 5e3)
    }

    function t(t) {
      const i = {};
      if (i['shown'] = !1, i.clicked = null, !1 === e())
        if (0 === document['querySelectorAll']("script[src*='client=ca-pub-" + c['publisherID'] + "']")['length']) {
          let e = document['createElement']("script");
          e['setAttribute']("crossorigin", 'anonymous'), e['async'] = !0, e.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-' + c['publisherID'], e['onload'] = function () {
            n(t)
          }, e['onerror'] = function () {
            const e = {};
            e['shown'] = !1, e.clicked = null, r(t) && t(e)
          }, document['head'].appendChild(e)
        } else n(t);
      else r(t) && t(i)
    }

    Object['defineProperties'](e, {
      init: {
        value: function (e) {
          if (null == l['get'](c['cookie'])) return t(e);
          const o = {};
          o['shown'] = !1, o['clicked'] = null, r(e) && e(o)
        }
      },
      show: {
        value: t
      }
    });

    let o = document['createElement']("style");
    o.textContent = ".fcBt{outline: none;border: none;padding: 0;margin: 0;position: absolute;top: 30px;right: 30px;width: 30px;height: 30px;display: flex;align-items:center;justify-content:center;border-radius:50%;background:#fff;box-shadow:0 0 20px rgba(0,0,0,.07);cursor: pointer;}.fcBt svg{width: 18px;height: 18px;fill: #686868 }.fcBt:hover span{opacity: 1;visibility: visible;top: calc(30px + 10px);}.fcBt span{position:absolute;top:30px;right:-15px;background:#fff;max-width:300px;width:180px;border-radius:10px;padding:10px;font-size:13px;line-height:1.1rem;box-shadow:0 0 20px rgba(0,0,0,.07);opacity:0;visibility:hidden;transition:all .2s ease;pointer-events: none;}.fcBt span::before{content:'';position: absolute;width:10px;height:10px;background:#fff;top:-4px;right:25px;transform:rotate(45deg);border-radius:2px;}.fcAd{position: fixed;top: -30%;right: -30%;bottom: -30%;left: -30%;background: rgba(0,0,0,.3);z-index: 999;}.fcFx{position: fixed;top: 0;right: 0;bottom: 0;left: 0;z-index: 999;padding: 20px;display: flex;align-items: center;justify-content: center;}.fcCn{background: #fff;padding: 10px;width: 100%;border-radius: 8px;max-width: 768px;}";
    document['head'].appendChild(o), window['popupAds'] = e;
  }({
    publisherID: google-adsense-id,
    adUnits: [id-adsense-slot-1, id-adsense-slot-2, id-adsense-slot-3],
    cookie: "__CLICK",
    message: "Click on Ads to support developer.",
    maxage: 24 * 60 * 60
  })
  popupAds.init()
/*]]>*/</script>

Các bạn nhớ thay thế các vị trí được đánh dấu trong đoạn code như:

  1. google-adsense-id: là id google adsense của bạn không có ca-pub-.
  2. id-adsense-slot-1, id-adsense-slot-2, id-adsense-slot-3: là id của các quảng cao khi bạn tạo, bạn muốn thêm bao nhiêu id cũng được.
  3. message: là thông báo khi người dùng bấm nút close.
  4. maxage: là thời gian hết hạn cookie và sẽ hiện thị lại popup sau khi hết hạn cookie được tính bằng đơn vị giây.

Nếu các bạn có thắc mắc gì về bài viết có thể comment trực tiếp xuống phía bên dưới phần bình luận, mình sẽ trả lời sớm nhất có thể. Demo các bạn có thể thấy khi truy cập vào bài viết này các bạn sẽ thấy popup quảng cáo xuất hiện.

Trên đây là hướng dẫn code Force Click Popup quảng cáo trên Blogger.
Nếu có bất cứ thắc mắc nào hãy comment ngay phía dưới cho mình biết nhé.
Chúc các bạn thành công và có một ngày làm việc thật hiệu quả!

Copyright © www.nldblog.com

Tôi là Nhật Nguyễn, một kỹ sư xây dựng. Nhưng thích tìm hiểu về mã nguồn lập trình web ☏.