সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আমাদের শুরু করা এবং মৌলিক ধারণা উদাহরণগুলিতে, Google প্রকাশক ট্যাগ (GPT) লাইব্রেরির display() পদ্ধতিটি একটি বিজ্ঞাপন স্লট নিবন্ধন এবং প্রদর্শন করতে ব্যবহৃত হয়। যাইহোক, এমন কিছু সময় আছে যখন বিজ্ঞাপন সামগ্রী লোড হওয়ার সময় আরও সুনির্দিষ্টভাবে নিয়ন্ত্রণ করার জন্য এই ক্রিয়াগুলিকে আলাদা করা পছন্দনীয় বা এমনকি প্রয়োজনীয়ও হতে পারে। যেমন, সম্মতি ম্যানেজমেন্ট প্ল্যাটফর্মের সাথে কাজ করার সময় বা ব্যবহারকারীর ক্রিয়াকলাপের ফলাফল হিসাবে বিজ্ঞাপন সামগ্রীর অনুরোধ করার সময়।
এই নির্দেশিকায় আমরা বিজ্ঞাপন সামগ্রীর লোডিং নিয়ন্ত্রণ করতে এবং চাহিদা অনুযায়ী নতুন বিজ্ঞাপন সামগ্রী আনতে GPT দ্বারা প্রদত্ত প্রক্রিয়াগুলি অন্বেষণ করব৷ এই উদাহরণের জন্য সম্পূর্ণ কোড ইভেন্ট ভিত্তিক অনুরোধের নমুনা পৃষ্ঠায় পাওয়া যাবে।
বিজ্ঞাপন লোডিং নিয়ন্ত্রণ করুন
ডিফল্টরূপে, display() পদ্ধতির আচরণ হল বিজ্ঞাপনের সামগ্রীকে একটি বিজ্ঞাপন স্লটে নিবন্ধন, অনুরোধ এবং রেন্ডার করা। PubAdsService.disableInitialLoad() পদ্ধতি ব্যবহার করে বিজ্ঞাপন সামগ্রীর স্বয়ংক্রিয় অনুরোধ এবং রেন্ডারিং অক্ষম করা যেতে পারে।
প্রারম্ভিক লোড অক্ষম করা হলে, display() এ কল শুধুমাত্র বিজ্ঞাপন স্লট নিবন্ধন করবে। দ্বিতীয় পদক্ষেপ নেওয়া না হওয়া পর্যন্ত কোনও বিজ্ঞাপন সামগ্রী লোড করা হবে না। এটি আপনাকে বিজ্ঞাপনের অনুরোধ করার সময় সঠিকভাবে নিয়ন্ত্রণ করতে দেয়।
অনিচ্ছাকৃত বিজ্ঞাপনের অনুরোধ এড়াতে, disableInitialLoad() পরিষেবা সক্রিয় করার আগে এবং display() কল করার আগে কল করতে হবে।
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Request GPT ads based on events." />
<title>Event-based ad requests</title>
<script
async
src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"
crossorigin="anonymous"
></script>
<script>
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(() => {
// Define the ad slot.
googletag
.defineSlot("/6355419/Travel", [728, 90], "div-for-slot")
.setTargeting("test", "event")
.addService(googletag.pubads());
// Disable initial load. // This prevents GPT from automatically fetching ads when display is called. googletag.pubads().disableInitialLoad(); googletag.enableServices();
});
</script>
<style></style>
</head>
<body>
<div id="div-for-slot" style="width: 300px; height: 250px"></div>
<script>
googletag.cmd.push(() => {
// Register the ad slot. // An ad will not be fetched until refresh is called. googletag.display("div-for-slot");
});
</script>
</body>
</html>
এই উদাহরণে, display() কল করা হলে কোনও বিজ্ঞাপনের অনুরোধ করা না হয় এবং কোনও বিজ্ঞাপন সামগ্রী রেন্ডার না হয় তা নিশ্চিত করে প্রাথমিক লোড অক্ষম করা হয়। স্লটটি একটি বিজ্ঞাপন গ্রহণ এবং প্রদর্শনের জন্য প্রস্তুত, কিন্তু স্লট রিফ্রেশ না হওয়া পর্যন্ত একটি বিজ্ঞাপন অনুরোধ করা হবে না৷
রিফ্রেশ
PubAdsService.refresh() পদ্ধতিটি নতুন বিজ্ঞাপন সামগ্রী সহ একটি স্লট বা স্লট তৈরি করতে ব্যবহৃত হয়। এই পদ্ধতিটি এমন স্লটগুলিতে ব্যবহার করা যেতে পারে যেগুলি এখনও কোনও সামগ্রী লোড করতে পারেনি ( disableInitialLoad() এর কারণে), বা ইতিমধ্যে জনবহুল স্লটের বিষয়বস্তু প্রতিস্থাপন করতে। যাইহোক, শুধুমাত্র display() কল করে নিবন্ধিত স্লটগুলিই রিফ্রেশ হওয়ার যোগ্য।
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Request GPT ads based on events." />
<title>Event-based ad requests</title>
<script
async
src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"
crossorigin="anonymous"
></script>
<script>
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(() => {
// Define the ad slot.
googletag
.defineSlot("/6355419/Travel", [728, 90], "div-for-slot")
.setTargeting("test", "event")
.addService(googletag.pubads());
// Disable initial load.
// This prevents GPT from automatically fetching ads when display is called.
googletag.pubads().disableInitialLoad();
googletag.enableServices();
});
</script>
<style></style>
</head>
<body>
<div id="div-for-slot" style="width: 300px; height: 250px"></div>
<button id="showAdButton">Show/Refresh Ad</button>
<script>
googletag.cmd.push(() => {
// Register the ad slot.
// An ad will not be fetched until refresh is called.
googletag.display("div-for-slot");
// Register click event handler. document.getElementById("showAdButton").addEventListener("click", () => { googletag.cmd.push(() => { googletag.pubads().refresh(); }); });
});
</script>
</body>
</html>
এই পরিবর্তিত উদাহরণে, যখন একজন ব্যবহারকারী "শো/রিফ্রেশ বিজ্ঞাপন" বোতামে ক্লিক করেন, তখন refresh() পদ্ধতি বলা হয়। এটি নতুন বিজ্ঞাপন সামগ্রী আনার জন্য একটি অনুরোধ ট্রিগার করে এবং এটি নিবন্ধিত স্লটে লোড করে, যে কোনো পূর্ব-বিদ্যমান সামগ্রীকে ওভাররাইট করে৷
মনে রাখবেন যে পূর্ববর্তী উদাহরণে refresh() পদ্ধতিটিকে কোনো প্যারামিটার ছাড়াই বলা হয়েছে, যা সমস্ত নিবন্ধিত বিজ্ঞাপন স্লটকে রিফ্রেশ করার প্রভাব রাখে। যাইহোক, refresh() পদ্ধতিতে স্লটের একটি অ্যারে পাস করে নির্দিষ্ট বিজ্ঞাপন স্লট রিফ্রেশ করাও সম্ভব। এর একটি উদাহরণের জন্য রিফ্রেশ বিজ্ঞাপন স্লট নমুনা দেখুন।
সর্বোত্তম অনুশীলন
refresh() এর সাথে কাজ করার সময়, কিছু সর্বোত্তম অনুশীলন রয়েছে যা মেনে চলা উচিত।
খুব তাড়াতাড়ি রিফ্রেশ করবেন না।
বিজ্ঞাপন স্লটগুলিকে খুব দ্রুত রিফ্রেশ করার ফলে আপনার বিজ্ঞাপনের অনুরোধগুলি থ্রোটল হতে পারে৷ এটি প্রতিরোধ করতে, প্রতি 30 সেকেন্ডে একবারের চেয়ে বেশি ঘন ঘন রিফ্রেশিং স্লটগুলি এড়িয়ে চলুন।
অপ্রয়োজনীয়ভাবে clear() কল করবেন না
একটি বিজ্ঞাপন স্লট রিফ্রেশ করার সময়, প্রথমে PubAdsService.clear() কল করবেন না৷ এটি অপ্রয়োজনীয়, যেহেতু refresh() নির্দিষ্ট স্লটের বিষয়বস্তু প্রতিস্থাপন করে, পূর্বে কোনো বিজ্ঞাপন সামগ্রী লোড করা হয়েছে কিনা তা নির্বিশেষে। refresh() কল করার আগে clear() কল করলে ব্যবহারকারীর কাছে ফাঁকা স্লট দৃশ্যমান হওয়ার পরিমাণ বৃদ্ধি পাবে।
শুধুমাত্র দর্শনযোগ্য বিজ্ঞাপন স্লট রিফ্রেশ করুন
refresh() ব্যবহার করে বিজ্ঞাপন স্লটের বিষয়বস্তু প্রতিস্থাপন করা যা কখনই দেখা যায় না তা উল্লেখযোগ্যভাবে আপনার ActiveView হার কমিয়ে দিতে পারে। কোন বিজ্ঞাপন স্লট কখন দর্শনযোগ্য হয়েছে তা নির্ধারণ করতে ImpressionViewableEvent ব্যবহার করা যেতে পারে, যেমনটি নিম্নলিখিত উদাহরণে দেখানো হয়েছে:
googletag.cmd.push(function(){varREFRESH_KEY='refresh';varREFRESH_VALUE='true';googletag.defineSlot('/6355419/Travel',[728,90],'div-for-slot').setTargeting(REFRESH_KEY,REFRESH_VALUE).setTargeting('test','event').addService(googletag.pubads());// Number of seconds to wait after the slot becomes viewable.varSECONDS_TO_WAIT_AFTER_VIEWABILITY=60;googletag.pubads().addEventListener('impressionViewable',function(event){varslot=event.slot;if(slot.getTargeting(REFRESH_KEY).indexOf(REFRESH_VALUE) > -1){setTimeout(function(){googletag.pubads().refresh([slot]);},SECONDS_TO_WAIT_AFTER_VIEWABILITY*1000);}});googletag.enableServices();});
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-05-09 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eGoogle Publisher Tag (GPT) allows you to separate ad slot registration and ad content loading for more control, useful for scenarios like consent management or user-triggered ad requests.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003edisableInitialLoad()\u003c/code\u003e prevents automatic ad requests upon calling \u003ccode\u003edisplay()\u003c/code\u003e, giving you control over when to fetch ads using the \u003ccode\u003erefresh()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003erefresh()\u003c/code\u003e method fetches new ad content for registered ad slots, either initially or to replace existing content; refreshing all slots or specific ones is possible.\u003c/p\u003e\n"],["\u003cp\u003eBest practices include avoiding excessive refreshes (more frequent than every 30 seconds), refraining from unnecessary \u003ccode\u003eclear()\u003c/code\u003e calls before \u003ccode\u003erefresh()\u003c/code\u003e, and prioritizing refreshing viewable ad slots to improve ActiveView rates.\u003c/p\u003e\n"]]],["The Google Publisher Tag (GPT) allows control over ad loading using `disableInitialLoad()`, preventing automatic ad requests upon `display()`. This method only registers the slot, enabling precise control over ad requests. The `refresh()` method populates slots with new content, either in previously registered slots or as replacement for existing content. Best practices include limiting refresh frequency to at least every 30 seconds, avoiding unnecessary `clear()` calls, and only refreshing viewable slots using the `impressionViewable` event.\n"],null,["# Control ad loading and refresh\n\nIn our getting started and basic concept examples, the Google Publisher Tag\n(GPT) library's [`display()`](/publisher-tag/reference#displayadunitpath,-size,-opt_div,-opt_clickurl) method is used\nto register and display an ad slot. However, there are times when it may be\npreferable or even necessary to separate these actions, in order to more\nprecisely control when ad content is loaded. For example, when working with a\nconsent management platform or requesting ad content as the result of a user\naction.\n\nIn this guide we'll explore the mechanisms provided by GPT to\ncontrol the loading of ad content and fetch new ad content on demand. Full code\nfor this example can be found on the [event based requests](/publisher-tag/samples/event-based-requests)\nsample page.\n\nControl ad loading\n------------------\n\nBy default, the behavior of the [`display()`](/publisher-tag/reference#displayadunitpath,-size,-opt_div,-opt_clickurl) method is to\nregister, request, and render ad content into an ad slot. The automatic\nrequesting and rendering of ad content can be disabled using\n[`googletag.setConfig({ disableInitialLoad: true })`](/publisher-tag/reference#googletag.config.PageSettingsConfig.disableInitialLoad).\n\nWith initial load disabled, calls to `display()` will only register the ad slot.\nNo ad content will be loaded until a second action is taken. This lets you\nprecisely control when ad requests are made.\n\nTo avoid making unintentional ad requests,\n`googletag.setConfig({ disableInitialLoad: true })` must be called before\nenabling the service and before calling `display()`. \n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n \u003chead\u003e\n \u003cmeta charset=\"utf-8\" /\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\u003e\n \u003cmeta name=\"description\" content=\"Request GPT ads based on events.\" /\u003e\n \u003ctitle\u003eEvent-based ad requests\u003c/title\u003e\n \u003cscript\n async\n src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\"\n crossorigin=\"anonymous\"\n \u003e\u003c/script\u003e\n \u003cscript\u003e\n window.googletag = window.googletag || { cmd: [] };\n\n googletag.cmd.push(() =\u003e {\n // Define the ad slot.\n googletag\n .defineSlot(\"/6355419/Travel\", [728, 90], \"div-for-slot\")\n .addService(googletag.pubads())\n .setConfig({\n targeting: {\n test: \"event\",\n },\n });\n\n // Disable initial load to prevent GPT from automatically fetching ads when\n // display() is called.\n googletag.setConfig({\n disableInitialLoad: true,\n });\n\n // Enable services.\n googletag.enableServices();\n });\n \u003c/script\u003e\n \u003cstyle\u003e\u003c/style\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"div-for-slot\" style=\"width: 300px; height: 250px\"\u003e\u003c/div\u003e\n \u003cscript\u003e\n googletag.cmd.push(() =\u003e {\n // Register the ad slot.\n // An ad will not be fetched until refresh is called.\n googletag.display(\"div-for-slot\");\n });\n \u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\nIn this example, initial load is disabled ensuring that no ad request is made\nand no ad content is rendered when `display()` is called. The slot is ready to\naccept and display an ad, but an ad request won't be made until the slot is\nrefreshed.\n\nRefresh\n-------\n\nThe [`PubAdsService.refresh()`](/publisher-tag/reference#googletag.PubAdsService_refresh) method is used to populate a\nslot or slots with new ad content. This method can be used on slots that have\nyet to load any content (due to\n`googletag.setConfig({ disableInitialLoad: true })`), or to replace the contents\nof an already populated slot. However, only slots which have been registered by\ncalling `display()` are eligible to be refreshed.\n**Important:** To comply with Google policy and enable your inventory to compete on Ad Exchange, you must [declare which portions of your inventory refresh](//support.google.com/admanager/answer/6286179). \n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n \u003chead\u003e\n \u003cmeta charset=\"utf-8\" /\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\u003e\n \u003cmeta name=\"description\" content=\"Request GPT ads based on events.\" /\u003e\n \u003ctitle\u003eEvent-based ad requests\u003c/title\u003e\n \u003cscript\n async\n src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\"\n crossorigin=\"anonymous\"\n \u003e\u003c/script\u003e\n \u003cscript\u003e\n window.googletag = window.googletag || { cmd: [] };\n\n googletag.cmd.push(() =\u003e {\n // Define the ad slot.\n googletag\n .defineSlot(\"/6355419/Travel\", [728, 90], \"div-for-slot\")\n .addService(googletag.pubads())\n .setConfig({\n targeting: {\n test: \"event\",\n },\n });\n\n // Disable initial load to prevent GPT from automatically fetching ads when\n // display() is called.\n googletag.setConfig({\n disableInitialLoad: true,\n });\n\n // Enable services.\n googletag.enableServices();\n });\n \u003c/script\u003e\n \u003cstyle\u003e\u003c/style\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"div-for-slot\" style=\"width: 300px; height: 250px\"\u003e\u003c/div\u003e\n \u003cbutton id=\"showAdButton\"\u003eShow/Refresh Ad\u003c/button\u003e\n \u003cscript\u003e\n googletag.cmd.push(() =\u003e {\n // Register the ad slot.\n // An ad will not be fetched until refresh is called.\n googletag.display(\"div-for-slot\");\n\n // Register click event handler.\n document.getElementById(\"showAdButton\").addEventListener(\"click\", () =\u003e {\n googletag.cmd.push(() =\u003e {\n googletag.pubads().refresh();\n });\n });\n });\n \u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\nIn this modified example, when a user clicks the \"Show/Refresh Ad\" button, the\n`refresh()` method is called. This triggers a request to fetch new ad content\nand load it into the registered slot, overwriting any pre-existing content.\n\nNote that in the preceding example the `refresh()` method is called with no\nparameters, which has the effect of refreshing **all** registered ad slots.\nHowever, it's also possible to refresh specific ad slots by passing an array of\nslots to the `refresh()` method. See the [Refresh ad slots](/publisher-tag/samples/refresh)\nsample for an example of this.\n\n### Best practices\n\nWhen working with `refresh()`, there are some best practices that should be\nadhered to.\n\n1. Don't refresh too quickly.\n\n Refreshing ad slots too quickly may cause your ad requests to be throttled.\n To prevent this, avoid refreshing slots more frequently than once every 30\n seconds.\n2. Don't call `clear()` unnecessarily\n\n When refreshing an ad slot, don't call\n [`PubAdsService.clear()`](/publisher-tag/reference#googletag.PubAdsService_clear) first. This is unnecessary, since\n `refresh()` replaces the contents of the specified slot, regardless of\n whether any ad content was previously loaded. Calling `clear()` immediately\n before calling `refresh()` will only increase the amount of time a blank slot\n is visible to the user.\n3. Only refresh viewable ad slots\n\n Using `refresh()` to replace the contents of ad slots that are never viewable\n can significantly lower your ActiveView rate. The\n [ImpressionViewableEvent](/publisher-tag/reference#googletag.events.impressionviewableevent) can be used to\n determine when an ad slot has become viewable, as shown in the following\n example: \n\n googletag.cmd.push(function() {\n var REFRESH_KEY = 'refresh';\n var REFRESH_VALUE = 'true';\n\n const slot = googletag.defineSlot('/6355419/Travel',[728, 90], 'div-for-slot')\n .addService(googletag.pubads());\n slot.setConfig({\n targeting: {\n [REFRESH_KEY]: REFRESH_VALUE,\n 'test': 'event'\n }\n });\n\n // Number of seconds to wait after the slot becomes viewable.\n var SECONDS_TO_WAIT_AFTER_VIEWABILITY = 60;\n\n googletag.pubads().addEventListener('impressionViewable', function(event) {\n var slot = event.slot;\n if (slot.getTargeting(REFRESH_KEY).indexOf(REFRESH_VALUE) \u003e -1) {\n setTimeout(function() {\n googletag.pubads().refresh([slot]);\n }, SECONDS_TO_WAIT_AFTER_VIEWABILITY * 1000);\n }\n });\n\n googletag.enableServices();\n });"]]