Parameters
Page Level Parameter Descriptions
These parameters only need to be specified once per page. They affect all units on the page.
Required
Parameter | Description and Examples |
---|---|
adPage
|
Required when the user navigates to the next results page or previous results page. The |
pubId
|
Required This is your AdSense client-ID. Your pubId is the part of your client-ID that comes after 'partner-'. For example, if your client-ID is 'partner-test-property', your pubId is 'test-property'. This is standard protocol for CSA. Example: 'pubId' : 'test-property' |
query
|
Required This is the search query entered by the user. The value of the query parameter should be unencoded. Examples: 'query' : 'flowers' 'query' : 'black & decker' 'query' : myQuery // myQuery is a variable containing the search query |
resultsPageBaseUrl
|
Required when there are related search units on the page. Specifies the URL of the search results page on which the search query is the related search term the user has clicked on. The resultsPageBaseUrl may include its own parameters, except the search query which will be appended automatically. Example: 'resultsPageBaseUrl' : 'http://www.example.com/search?a=v1&b=v2' |
Optional
Parameter | Description and Examples | |||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
linkTarget
|
Optional Specifies whether clicking on an ad or related search term opens up in the same window or a new window. The default is '_top'. This parameter can also be used at the unit level.
Example: 'linkTarget' : '_blank' |
|||||||||||||||||||||||||||||||||||||||||||||||||||
maxTermLength
|
Optional Specifies the maximum number of characters of a related search term including spaces. No maximum if not set. Example: 'maxTermLength' : 50 |
|||||||||||||||||||||||||||||||||||||||||||||||||||
resultsPageQueryParam
|
Optional Specifies the name of the URL parameter for the search query on the search results page. Defaults to ‘q’ if not specified. Example: 'resultsPageQueryParam' : 'query' |
Parameter | Description and Examples | |||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
adsafe
|
Optional Specifies the filtering rules that Google should apply to ads matching the search query. The following are the valid settings for adsafe and the effect each value has on returned ads:
By default adsafe is set to high. Example: 'adsafe': 'medium' |
|||||||||||||||||||||||||||||||||||||||||||||||||||
adtest
|
Optional The adtest parameter is used to indicate that a request for ads is a test. When the adtest parameter has a value of on, Google treats the request as a test and does not count the ad impressions or track the clickthrough results. When the adtest parameter has a value of on, you do not generate any revenue. Use this parameter when testing, but do not use it in production systems or you will not be paid for ads that you display. The default adtest value is off. Example: 'adtest' : 'on' |
|||||||||||||||||||||||||||||||||||||||||||||||||||
channel
|
Optional You may include an AdSense for Search channel for tracking the performance of different pages. Use the unique channel ID created in your AdSense account or by your Technical Account Manager. Learn more about channels here. Multiple channels should be separated by the '+' symbol. Examples: 'channel' : 'testA' 'channel' : 'testA+testB' |
|||||||||||||||||||||||||||||||||||||||||||||||||||
hl
|
Optional This parameter identifies the language that the requested ads should target. The default value is en. Google supports all AdWords API language codes. Note: Advertisers specify the languages that their ads target. If you include this parameter in your request, Google only returns ads that are targeted for that language or targeted for all languages but it does not guarantee that the ad text will be in the specified language. Typically, you should set the hl parameter to the primary language of the page from which this parameter is sent. Examples: 'hl' : 'es' |
|||||||||||||||||||||||||||||||||||||||||||||||||||
ie
|
Optional The The default
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
oe
|
Optional The The default |
|||||||||||||||||||||||||||||||||||||||||||||||||||
personalizedAds
|
Optional Specifies whether users have consented to allowing the publisher to share personal information with Google for the purpose of personalized advertising.
By default personalizedAds is set to true. Example: 'personalizedAds': false |
|||||||||||||||||||||||||||||||||||||||||||||||||||
styleId
|
Optional Specifies the ID of the custom search style to be applied to the ad or related search units on the page. Learn more about using custom search styles. Note that with the styleId set for a request, ads or related searches will be rendered with the style, and legacy styling parameters will be ignored. If styleId is not specified in the request, a system default style will be rendered. Example: 'styleId': '1234567890' |
Parameter | Description and Examples |
---|---|
container
|
Required The id of the empty ad container <div> where the ad should appear.
Example: 'container' : 'afscontainer1' |
maxTop
|
Required when the ad unit is above the search results. Use this parameter to specify the number of ads to be shown on the top ad unit. Note: This parameter is used in place of the 'number' parameter. This ad unit should be wide enough so the first line of the ads doesn't wrap. Using the maxTop parameter on any other placement on the page is a policy violation. Example: 'maxTop' : 4 |
width
|
Required Specifies the width of the ad or related search unit in pixels. Example: 'width' : '700px' 'width' : 700 |
Configuration Settings
Parameter | Description and Examples |
---|---|
adLoadedCallback
|
Optional Allows an action to be performed when ad calls are finished. The callback function takes the container name of the ad or related search unit and a boolean. The boolean is set to true when there is at least one ad or related search term to display and false when there are none returned. It is important to test your callback function to ensure it doesn't generate any errors, especially those that might interfere with the loading of your page. Example: var adblock1 = { 'container' : 'afscontainer1', 'adLoadedCallback' : function(containerName, adsLoaded) { if (adsLoaded) { try { // Most likely do nothing } catch (e) { alert ("Error in callback function"); // Do something to handle error gracefully } else { // As you always do when there is no ad coverage from Google } } }; |
number
|
Optional The number of ads which should appear in this unit. The default value is 2. Example: 'number' : 4 |
relatedSearches
|
Optional The number of related searches that should appear in this unit. Defaults to 0 if not specified. Example: 'relatedSearches' : 4 |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-11-17 UTC.