Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Tag publisher di Google (GPT) è una libreria di tag annuncio per
in Google Ad Manager.
Puoi utilizzare GPT per creare dinamicamente richieste di annunci.
GPT utilizza dettagli chiave quali il codice dell'unità pubblicitaria, le dimensioni dell'annuncio e
il targeting personalizzato, crea la richiesta e visualizza l'annuncio nelle pagine Web.
Di seguito sono riportati alcuni esempi che puoi utilizzare per iniziare a utilizzare GPT. Se
hai bisogno di ulteriore assistenza con GPT, consulta le informazioni su
opzioni.
Visualizzare un annuncio di prova
L'esempio seguente illustra la creazione di una pagina di test che
utilizza GPT per caricare un annuncio generico dalla rete di prova di Google.
Questo codice garantisce innanzitutto che l'oggetto googletag sia disponibile, poi mette in coda un
che crea un'area annuncio
e attiva GPT.
L'area annuncio di questo esempio caricherà un annuncio di dimensioni 300x250 dall'annuncio
unità specificata dal percorso /6355419/Travel/Europe/France/Paris. L'annuncio verrà
visualizzato in un elemento <div id="banner-ad"> nel corpo della pagina, che
verrà aggiunto successivamente.
<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>
Specifica dove verrà visualizzato l'annuncio
Specifica in quale punto della pagina verrà visualizzato l'annuncio aggiungendo il seguente codice alla
il <body> del documento HTML.
Tieni presente che l'ID di questo <div> corrisponde all'ID specificato al momento della definizione
area annuncio.
<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>
Visualizza l'anteprima della pagina di test
Salva il file hello-gpt.html e aprilo in un browser web. Una volta caricati,
la pagina visualizzerà un annuncio di prova nel corpo della pagina web.
Visualizza il tuo annuncio
Per pubblicare il tuo annuncio, utilizza il file hello-gpt.html da Mostra un test
ad, poi sostituisci il codice nell'intestazione con il codice che specifica
l'inventario della tua rete Ad Manager.
Genera un tag annuncio per l'unità pubblicitaria da visualizzare. Scopri di più su
generando tag annuncio nel
Centro assistenza Ad Manager.
Copia il codice del tag annuncio fornito nella sezione Intestazione documento e utilizzalo
per sostituire il codice corrispondente nel <head> del documento HTML.
[null,null,["Ultimo aggiornamento 2025-05-09 UTC."],[[["\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."]]