Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Google Publisher Tag (GPT) est une bibliothèque d'ajout de tags d'emplacement publicitaire
Google Ad Manager.
Vous pouvez utiliser GPT pour créer des demandes d'annonces de manière dynamique.
GPT prend des détails clés tels que le code du bloc d'annonces, la taille de l'annonce
un ciblage personnalisé, crée la demande et diffuse l'annonce sur des pages Web.
Voici quelques exemples que vous pouvez utiliser pour commencer à utiliser GPT. Si
si vous avez besoin d'aide supplémentaire concernant GPT, consultez la page d'assistance
options.
Afficher une annonce test
L'exemple suivant vous montre comment créer une page de test
utilise GPT pour charger une annonce générique à partir du réseau de test de Google.
<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>
<style></style>
</head>
Définir un espace publicitaire
Définissez un espace publicitaire, puis initialisez GPT à l'aide de la méthode
googletag.enableServices().
Ce code vérifie d'abord que l'objet googletag est disponible, puis met un
qui crée un espace publicitaire
et active GPT.
Dans cet exemple, l'espace publicitaire charge une annonce de taille 300x250 à partir de l'annonce
unité spécifiée par le chemin d'accès /6355419/Travel/Europe/France/Paris. L'annonce sera
s'affiche dans un élément <div id="banner-ad"> du corps de la page, ce qui
seront ajoutées par la suite.
<ph type="x-smartling-placeholder">
<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>
Indiquer l'emplacement de diffusion de l'annonce
Indiquez l'emplacement de l'annonce sur la page en ajoutant le code suivant à
l'élément <body> du document HTML.
Notez que l'ID de ce <div> correspond à celui spécifié lors de la définition de
dans l'espace publicitaire.
<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>
Prévisualiser la page de test
Enregistrez le fichier hello-gpt.html et ouvrez-le dans un navigateur Web. Une fois le chargement terminé,
la page affichera une annonce test dans le corps de la page Web.
Diffusez votre propre annonce
Pour diffuser votre propre annonce, utilisez le fichier hello-gpt.html de la section Afficher un test
l'annonce, puis remplacez le code de l'en-tête par le code spécifiant
de votre propre réseau Ad Manager.
Générez un tag d'emplacement publicitaire pour le bloc d'annonces à afficher. En savoir plus sur
générer des tags d'emplacement publicitaire
Centre d'aide Ad Manager.
Copiez le code du tag d'emplacement publicitaire figurant dans la section En-tête du document et utilisez-le.
pour remplacer le code correspondant dans la section <head> de votre document HTML.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/05/09 (UTC).
[null,null,["Dernière mise à jour le 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."]]