با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Google Publisher Tag (GPT) یک کتابخانه برچسبگذاری تبلیغات برای Google Ad Manager است.
می توانید از GPT برای ایجاد پویا درخواست های تبلیغاتی استفاده کنید. GPT جزئیات کلیدی مانند کد واحد تبلیغات، اندازه آگهی و هدفگیری سفارشی را میگیرد، درخواست را ایجاد میکند و آگهی را در صفحات وب نمایش میدهد.
در اینجا چند نمونه وجود دارد که می توانید برای شروع با GPT از آنها استفاده کنید. اگر در مورد GPT به راهنمایی بیشتری نیاز دارید، گزینههای پشتیبانی را ببینید.
نمایش یک تبلیغ آزمایشی
مثال زیر شما را در ایجاد یک صفحه آزمایشی راهنمایی می کند که از GPT برای بارگیری یک آگهی عمومی از شبکه آزمایشی Google استفاده می کند.
کد کامل این مثال را میتوانید در صفحه نمونه آگهی آزمایشی مشاهده کنید.
یک سند HTML اولیه ایجاد کنید
در یک ویرایشگر متن، یک سند HTML اصلی به نام hello-gpt.html ایجاد کنید.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Display a fixed-sized test ad." />
<title>Display a test ad</title>
<style></style>
</head>
<body>
</body>
</html>
کتابخانه GPT را بارگیری کنید
با افزودن موارد زیر به <head> سند HTML، کتابخانه GPT را بارگیری کنید.
این کد ابتدا اطمینان میدهد که شی googletag در دسترس است، سپس دستوری را در صف قرار میدهد که یک شکاف تبلیغاتی ایجاد میکند و GPT را فعال میکند.
شکاف آگهی در این مثال، تبلیغی به اندازه 300x250 را از واحد تبلیغاتی مشخص شده توسط مسیر /6355419/Travel/Europe/France/Paris بارگیری می کند. تبلیغ در یک عنصر <div id="banner-ad"> در بدنه صفحه نمایش داده می شود که در ادامه اضافه خواهد شد.
network-code یک شناسه منحصر به فرد برای شبکه Ad Manager است که واحد تبلیغات به آن تعلق دارد
parent-ad-unit-code کدهای همه واحدهای تبلیغاتی والد است (فقط برای واحدهای تبلیغاتی سطح بالا اعمال می شود)
ad-unit-code کدی است که واحد تبلیغات نمایش داده می شود
توجه داشته باشید که همه کدهای واحد تبلیغاتی که در مسیر واحد تبلیغات قرار دارند باید از قوانین قالب بندی مشخص شده توسط Ad Manager پیروی کنند.
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Display a fixed-sized test ad." />
<title>Display a test ad</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 an ad slot for div with id "banner-ad". googletag .defineSlot("/6355419/Travel/Europe/France/Paris", [300, 250], "banner-ad") .addService(googletag.pubads()); // Enable the PubAdsService. googletag.enableServices(); }); </script>
<style></style>
</head>
محل نمایش آگهی را مشخص کنید
با افزودن کد زیر به <body> سند HTML، مکان نمایش آگهی را در صفحه مشخص کنید.
توجه داشته باشید که شناسه این <div> با شناسه مشخص شده هنگام تعریف جایگاه آگهی مطابقت دارد.
<body>
<div id="banner-ad" style="width: 300px; height: 250px"></div> <script> googletag.cmd.push(() => { // Request and render an ad for the "banner-ad" slot. googletag.display("banner-ad"); }); </script>
</body>
پیش نمایش صفحه آزمون
فایل hello-gpt.html را ذخیره کرده و در یک مرورگر وب باز کنید. پس از بارگذاری، صفحه یک تبلیغ آزمایشی در بدنه صفحه وب نمایش می دهد.
تبلیغ خود را نمایش دهید
برای نمایش تبلیغ خود، از فایل hello-gpt.html از Display a test ad استفاده کنید، سپس کد موجود در سربرگ را با کد مشخص کننده موجودی از شبکه Ad Manager خود جایگزین کنید.
یک برچسب تبلیغاتی برای واحد تبلیغاتی که میخواهید نمایش دهید ایجاد کنید. درباره ایجاد برچسب های تبلیغاتی در مرکز راهنمای Ad Manager بیشتر بیاموزید.
کد تگ آگهی ارائه شده در بخش هدر سند را کپی کنید و از آن برای جایگزینی کد مربوطه در <head> سند HTML خود استفاده کنید.
تاریخ آخرین بهروزرسانی 2025-05-09 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-05-09 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eGoogle Publisher Tag (GPT) is an ad tagging library for Google Ad Manager that dynamically builds ad requests.\u003c/p\u003e\n"],["\u003cp\u003eGPT uses key details like ad unit code, size, and targeting to build the request and display ads on web pages.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can find sample code and detailed instructions to implement GPT for displaying test and live ads.\u003c/p\u003e\n"],["\u003cp\u003eTo display live ads, publishers need an active line item in their Ad Manager network and an ad tag generated for the specific ad unit.\u003c/p\u003e\n"]]],["GPT, a Google Ad Manager tagging library, dynamically builds ad requests. To display a test ad, create an HTML file, load the GPT library, and define an ad slot with `googletag.defineSlot()`, including the ad unit path (e.g., `/6355419/Travel/Europe/France/Paris`) and dimensions. Enable GPT with `googletag.enableServices()`. Add a `\u003cdiv\u003e` element to the body matching the slot's ID and use `googletag.display()` to render the ad. Replace test ad details with your Ad Manager network's ad tag to show your ads.\n"],null,["# Get Started with Google Publisher Tag\n\nThe Google Publisher Tag (GPT) is an ad tagging library for\nGoogle Ad Manager.\n\nYou can use GPT to dynamically build ad requests.\nGPT takes key details like the ad unit code, ad size, and\ncustom targeting, builds the request, and displays the ad on web pages.\n\nFor more details on GPT, see the\n[Ad Manager help center](//support.google.com/admanager/answer/181073).\n\nHere are some samples you can use to get started with GPT. If\nyou need more help with GPT, see the [support\noptions](/publisher-tag/support/feedback-questions).\n\nDisplay a test ad\n-----------------\n\nThe following example walks you through creating a test page that\nuses GPT to load a generic ad from Google's test network.\n\nFull code for this example can be found on the\n[display a test ad](/publisher-tag/samples/display-test-ad) sample page.\n\n1. Create a basic HTML document\n\n In a text editor, create a basic HTML document called `hello-gpt.html`. \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=\"Display a fixed-sized test ad.\" /\u003e\n \u003ctitle\u003eDisplay a test ad\u003c/title\u003e\n \u003cstyle\u003e\u003c/style\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n ```\n2. Load the GPT library\n\n Load the GPT library by adding the following to the\n `\u003chead\u003e` of the HTML document.\n\n This code loads the GPT library from\n \u003chttps://securepubads.g.doubleclick.net/tag/js/gpt.js\u003e. Once the library has\n fully loaded, it processes any queued commands in the\n [`googletag`](/publisher-tag/reference#googletag) object.\n **Important:** Only [load GPT from a Google domain](/publisher-tag/guides/general-best-practices#load_from_an_official_source). \n\n ```html\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=\"Display a fixed-sized test ad.\" /\u003e\n \u003ctitle\u003eDisplay a test ad\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 \u003cstyle\u003e\u003c/style\u003e\n \u003c/head\u003e\n ```\n3. Define an ad slot\n\n Define an ad slot and initialize GPT using the\n [`googletag.enableServices()`](/publisher-tag/reference#googletag.enableServices) method.\n\n This code first ensures the googletag object is available, then queues a\n command which constructs an ad slot and enables GPT.\n\n The ad slot in this example will load an ad of size `300x250` from the ad\n unit specified by path `/6355419/Travel/Europe/France/Paris`. The ad will be\n displayed in a `\u003cdiv id=\"banner-ad\"\u003e` element in the body of the page, which\n will be added next.\n\n \u003cbr /\u003e\n\n | Ad unit path follows the format `/`\u003cvar translate=\"no\"\u003enetwork-code\u003c/var\u003e`/[`\u003cvar translate=\"no\"\u003eparent-ad-unit-code\u003c/var\u003e`/.../]`\u003cvar translate=\"no\"\u003ead-unit-code\u003c/var\u003e, where:\n |\n | \u003cbr /\u003e\n |\n | - \u003cvar translate=\"no\"\u003enetwork-code\u003c/var\u003e is a [unique identifier](//support.google.com/admanager/answer/7674889#network-code) for the Ad Manager network the ad unit belongs to\n | - \u003cvar translate=\"no\"\u003eparent-ad-unit-code\u003c/var\u003e are the codes of all parent ad units (only applies to non-top level ad units)\n | - \u003cvar translate=\"no\"\u003ead-unit-code\u003c/var\u003e is the code for the ad unit to be displayed\n |\n | Note that all ad unit codes included in the ad unit path must adhere to the\n | [formatting rules](//support.google.com/admanager/answer/1628457#ad-unit-codes) specified by\n | Ad Manager.\n\n \u003cbr /\u003e\n\n ```html\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=\"Display a fixed-sized test ad.\" /\u003e\n \u003ctitle\u003eDisplay a test ad\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 an ad slot for div with id \"banner-ad\".\n googletag\n .defineSlot(\"/6355419/Travel/Europe/France/Paris\", [300, 250], \"banner-ad\")\n .addService(googletag.pubads());\n\n // Enable the PubAdsService.\n googletag.enableServices();\n });\n \u003c/script\u003e\n \u003cstyle\u003e\u003c/style\u003e\n \u003c/head\u003e\n ```\n4. Specify where the ad will appear\n\n Specify where the ad will appear on the page by adding the following code to\n the `\u003cbody\u003e` of the HTML document.\n\n Note that the ID of this `\u003cdiv\u003e` matches the ID specified when defining the\n ad slot. \n\n ```html\n \u003cbody\u003e\n \u003cdiv id=\"banner-ad\" style=\"width: 300px; height: 250px\"\u003e\u003c/div\u003e\n \u003cscript\u003e\n googletag.cmd.push(() =\u003e {\n // Request and render an ad for the \"banner-ad\" slot.\n googletag.display(\"banner-ad\");\n });\n \u003c/script\u003e\n \u003c/body\u003e\n ```\n5. Preview the test page\n\n Save the `hello-gpt.html` file and open it in a web browser. Once loaded,\n the page will display a test ad in the body of the web page.\n | **Caution:** If you don't see an ad, ensure that the div ID specified in the `\u003chead\u003e` of the page matches the ID of the `\u003cdiv\u003e` element you added to the `\u003cbody\u003e` of the page.\n\nDisplay your own ad\n-------------------\n\nTo display your own ad, use the `hello-gpt.html` file from [Display a test\nad](#generic-ad), then replace the code in the header with code specifying\ninventory from your own Ad Manager network.\n| **Note:** Before you can display an ad from your Ad Manager network, you need to make sure there's an active line item already trafficked in the \"Ready\" status. Learn more about creating line items in the [Ad Manager help center](//support.google.com/admanager/answer/82236).\n\n1. Generate an ad tag for the ad unit you'd like to display. Learn more about\n generating ad tags in the\n [Ad Manager help center](//support.google.com/admanager/answer/177207).\n\n2. Copy the ad tag code provided in the **Document header** section and use it\n to replace the corresponding code in the `\u003chead\u003e` of your HTML document.\n\n **Caution:** ensure that the width, height, and ID of the `\u003cdiv\u003e` declared in the body of the page matches the width, height, and ID of the ad slot defined in the ad tag code. \n\n \u003chead\u003e\n \u003cmeta charset=\"utf-8\"\u003e\n \u003ctitle\u003eHello GPT\u003c/title\u003e\n \u003cscript src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\" crossorigin=\"anonymous\" async\u003e\u003c/script\u003e\n \\\u003cscript\\\u003e\n window.googletag = window.googletag \\|\\| {cmd: \\[\\]};\n googletag.cmd.push(function() {\n googletag\n .defineSlot(\"\u003cvar translate=\"no\"\u003ead-unit-path\u003c/var\u003e\", \\[\u003cvar translate=\"no\"\u003ewidth\u003c/var\u003e, \u003cvar translate=\"no\"\u003eheight\u003c/var\u003e\\], \"\u003cvar translate=\"no\"\u003ediv-id\u003c/var\u003e\")\n .addService(googletag.pubads());\n googletag.enableServices();\n });\n \\\u003c/script\\\u003e\n \u003c/head\u003e\n\n3. Save the updated `hello-gpt.html` file and open it in a web browser."]]