'nonce' NonceLoader를 사용하여 PAL에서 생성한 암호화된 단일 문자열입니다.
PAL SDK는 새로운 각 스트림 요청에
생성된 nonce입니다. 하지만 nonce는
동일한 스트림으로 전송할 수 있습니다. PAL을 사용하여 nonce를 생성하는 샘플 앱을 보려면 다음을 다운로드하세요.
GitHub에서 HTML5 예시를 확인하세요.
letvideoElement;letnonceLoader;letmanagerPromise;letnonceManager;letstorageConsent=true;letplaybackStarted=false;/** * A placeholder for the publisher's own method of obtaining user * consent, either by integrating with a CMP or based on other * methods the publisher chooses to handle storage consent. * @return {boolean} Whether storage consent has been given. */functiongetConsentToStorage(){returnstorageConsent;}/** * Initializes the PAL loader. */functioninit(){constvideoElement=document.getElementById('placeholder-video');videoElement.addEventListener('mousedown',(e)=>voidonVideoTouch(e));videoElement.addEventListener('touchstart',(e)=>voidonVideoTouch(e));videoElement.addEventListener('play',()=>{if(!playbackStarted){sendPlaybackStart();playbackStarted=true;}});videoElement.addEventListener('ended',()=>voidsendPlaybackEnd());videoElement.addEventListener('error',()=>{console.log("Video error: "+videoElement.error.message);sendPlaybackEnd();});document.getElementById('generate-nonce').addEventListener('click',generateNonce);// The default value for `allowStorage` is false, but can be// changed once the appropriate consent has been gathered.constconsentSettings=newgoog.pal.ConsentSettings();consentSettings.allowStorage=getConsentToStorage();nonceLoader=newgoog.pal.NonceLoader(consentSettings);}/** * Generates a nonce with sample arguments and logs it to the console. * * The NonceRequest parameters set here are example parameters. * You should set your parameters based on your own app characteristics. */functiongenerateNonce(){constrequest=newgoog.pal.NonceRequest();request.adWillAutoPlay=true;request.adWillPlayMuted=false;request.continuousPlayback=false;request.descriptionUrl='https://example.com';request.iconsSupported=true;request.playerType='Sample Player Type';request.playerVersion='1.0';request.ppid='Sample PPID';request.sessionId='Sample SID';// Player support for VPAID 2.0, OMID 1.0, and SIMID 1.1request.supportedApiFrameworks='2,7,9';request.url='https://developers.google.com/ad-manager/pal/html5';request.videoHeight=480;request.videoWidth=640;managerPromise=nonceLoader.loadNonceManager(request);managerPromise.then((manager)=>{nonceManager=manager;console.log('Nonce generated: '+manager.getNonce());}).catch((error)=>{console.log('Error generating nonce: '+error);});}init();
광고 요청에 nonce 첨부
생성된 nonce를 사용하려면 givn 매개변수와 함께 광고 태그를 추가하고
nonce 값).
pal.js
/** * The ad tag for your ad request, for example: * https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator= * * For more sample ad tags, see https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags */constDEFAULT_AD_TAG="Your ad tag";...managerPromise=nonceLoader.loadNonceManager(request);managerPromise.then((manager)=>{nonceManager=manager;console.log('Nonce generated: '+manager.getNonce());// Append the nonce to the ad tag URL.makeAdRequest(DEFAULT_AD_TAG+"&givn="+nonceString);})
재생 이벤트 추적
마지막으로 플레이어의 다양한 이벤트 핸들러를 구현해야 합니다. 대상
테스트 목적으로 이러한 이벤트를 버튼 클릭 이벤트에 연결할 수 있지만,
구현 시 적절한 플레이어 이벤트에 의해 트리거됩니다.
pal.js
/** * Informs PAL that an ad click has occurred. How this function is * called will vary depending on your ad implementation. */functionsendAdClick(){nonceManager?.sendAdClick();}/** * Handles the user touching on the video element, passing it to PAL. * @param {!TouchEvent|!MouseEvent} touchEvent */functiononVideoTouch(touchEvent){nonceManager?.sendAdTouch(touchEvent);}/** Informs PAL that playback has started. */functionsendPlaybackStart(){nonceManager?.sendPlaybackStart();}/** Informs PAL that playback has ended. */functionsendPlaybackEnd(){nonceManager?.sendPlaybackEnd();}
구현에서 동영상이 완료되면 sendPlaybackStart를 호출해야 합니다.
시작되어야 합니다. 동영상이 완료되면 sendPlaybackEnd를 호출해야 합니다.
종료될 수 있습니다. sendAdClick는
시청자가 광고를 클릭할 때 sendAdTouch는 모든 터치 상호작용에서 호출되어야 합니다.
발생합니다.
Ad Manager는 nonce 값을 식별하기 위해 givn=를 찾습니다. 타사 광고
서버는 자체 매크로를 지원해야 함(예:
%%custom_key_for_google_nonce%%)하고 nonce 쿼리 매개변수로 바꿉니다.
사용할 수 있습니다 이 작업을 수행하는 방법에 대해 자세히 알아보기
외부 광고 서버 설명서에 나와 있습니다.
작업이 끝났습니다. 이제 PAL SDK에서 nonce 매개변수가 전파되어야 합니다.
중간 서버를 통해 전달되고 Google Ad Manager로 전달됩니다. 이렇게 하면
Google Ad Manager를 통해
수익을 창출할 수 있습니다
[[["이해하기 쉬움","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-08-21(UTC)"],[[["\u003cp\u003eA nonce is an encrypted string generated by the PAL SDK's \u003ccode\u003eNonceLoader\u003c/code\u003e and is required for each new stream request, although it can be reused for multiple ad requests within the same stream.\u003c/p\u003e\n"],["\u003cp\u003eGenerating a nonce involves creating a \u003ccode\u003eNonceRequest\u003c/code\u003e object with specific parameters like ad playback details, player information, and supported API frameworks, then using the \u003ccode\u003eNonceLoader\u003c/code\u003e to create a \u003ccode\u003eNonceManager\u003c/code\u003e, which holds the generated nonce.\u003c/p\u003e\n"],["\u003cp\u003eTo use the generated nonce, it must be appended to the ad tag URL as the \u003ccode\u003egivn\u003c/code\u003e parameter before making ad requests, and it is recommended to migrate from the deprecated \u003ccode\u003epaln\u003c/code\u003e parameter to \u003ccode\u003egivn\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eImplementing event handlers such as \u003ccode\u003esendAdClick\u003c/code\u003e, \u003ccode\u003eonVideoTouch\u003c/code\u003e, \u003ccode\u003esendPlaybackStart\u003c/code\u003e, and \u003ccode\u003esendPlaybackEnd\u003c/code\u003e is essential for tracking user interactions and playback status, which PAL requires to be properly informed.\u003c/p\u003e\n"],["\u003cp\u003eThird-party ad servers can forward the nonce to Google Ad Manager by including it in their ad tag requests using the \u003ccode\u003egivn\u003c/code\u003e parameter, ensuring proper propagation of the nonce and enabling enhanced monetization through Google Ad Manager.\u003c/p\u003e\n"]]],[],null,["# Get Started\n\nGenerate a nonce\n----------------\n\nA \"nonce\" is a single encrypted string generated by PAL using the `NonceLoader`.\nThe PAL SDK requires each new stream request to be accompanied by a newly\ngenerated nonce. However, nonces may be reused for multiple ad requests within\nthe same stream. To see a sample app that uses PAL to generate a nonce, download\nthe HTML5 example from [GitHub](//github.com/googleads/googleads-pal).\n\nTo generate a nonce using the PAL SDK, create an HTML file and add the\nfollowing:\n\n#### pal.html\n\n \u003chtml\u003e\n \u003chead\u003e\u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"placeholder-video\"\u003e\u003c/div\u003e\n \u003cbutton id=\"generate-nonce\"\u003eGenerate Nonce\u003c/button\u003e\n \u003cscript src=\"//imasdk.googleapis.com/pal/sdkloader/pal.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"pal.js\"\u003e\u003c/script\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n\nThen, create a JavaScript file and add the following:\n\n#### pal.js\n\n let videoElement;\n let nonceLoader;\n let managerPromise;\n let nonceManager;\n let storageConsent = true;\n let playbackStarted = false;\n\n /**\n * A placeholder for the publisher's own method of obtaining user\n * consent, either by integrating with a CMP or based on other\n * methods the publisher chooses to handle storage consent.\n * @return {boolean} Whether storage consent has been given.\n */\n function getConsentToStorage() {\n return storageConsent;\n }\n\n /**\n * Initializes the PAL loader.\n */\n function init() {\n const videoElement = document.getElementById('placeholder-video');\n videoElement.addEventListener('mousedown', (e) =\u003e void onVideoTouch(e));\n videoElement.addEventListener('touchstart', (e) =\u003e void onVideoTouch(e));\n videoElement.addEventListener('play', () =\u003e {\n if (!playbackStarted) {\n sendPlaybackStart();\n playbackStarted = true;\n }\n });\n videoElement.addEventListener('ended', () =\u003e void sendPlaybackEnd());\n videoElement.addEventListener('error', () =\u003e {\n console.log(\"Video error: \" + videoElement.error.message);\n sendPlaybackEnd();\n });\n\n document.getElementById('generate-nonce')\n .addEventListener('click', generateNonce);\n\n // The default value for `allowStorage` is false, but can be\n // changed once the appropriate consent has been gathered.\n const consentSettings = new goog.pal.ConsentSettings();\n consentSettings.allowStorage = getConsentToStorage();\n\n nonceLoader = new goog.pal.NonceLoader(consentSettings);\n }\n\n /**\n * Generates a nonce with sample arguments and logs it to the console.\n *\n * The NonceRequest parameters set here are example parameters.\n * You should set your parameters based on your own app characteristics.\n */\n function generateNonce() {\n const request = new goog.pal.NonceRequest();\n request.adWillAutoPlay = true;\n request.adWillPlayMuted = false;\n request.continuousPlayback = false;\n request.descriptionUrl = 'https://example.com';\n request.iconsSupported = true;\n request.playerType = 'Sample Player Type';\n request.playerVersion = '1.0';\n request.ppid = 'Sample PPID';\n request.sessionId = 'Sample SID';\n // Player support for VPAID 2.0, OMID 1.0, and SIMID 1.1\n request.supportedApiFrameworks = '2,7,9';\n request.url = 'https://developers.google.com/ad-manager/pal/html5';\n request.videoHeight = 480;\n request.videoWidth = 640;\n\n managerPromise = nonceLoader.loadNonceManager(request);\n managerPromise\n .then((manager) =\u003e {\n nonceManager = manager;\n console.log('Nonce generated: ' + manager.getNonce());\n })\n .catch((error) =\u003e {\n console.log('Error generating nonce: ' + error);\n });\n }\n\n init();\n\nAttach your nonce to the ad request\n-----------------------------------\n\nTo use the generated nonce, append your ad tag with a `givn` parameter and the\nnonce value, before making your ad requests.\n| **Caution:** If you previously provided a nonce using the `paln` parameter, it is strongly recommended to migrate to `givn` and stop sending `paln`. If both parameters are included, it is undefined behavior regarding which nonce one is used.\n\n#### pal.js\n\n /\\*\\*\n \\* The ad tag for your ad request, for example:\n \\* https://pubads.g.doubleclick.net/gampad/ads?sz=640x480\\&iu=/124319096/external/single_ad_samples\\&ciu_szs=300x250\\&impl=s\\&gdfp_req=1\\&env=vp\\&output=vast\\&unviewed_position_start=1\\&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear\\&correlator=\n \\*\n \\* For more sample ad tags, see https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags\n \\*/\n const DEFAULT_AD_TAG = \"Your ad tag\";\n\n ...\n\n managerPromise = nonceLoader.loadNonceManager(request);\n managerPromise\n .then((manager) =\u003e {\n nonceManager = manager;\n console.log('Nonce generated: ' + manager.getNonce());\n // Append the nonce to the ad tag URL.\n makeAdRequest(DEFAULT_AD_TAG + \"\\&givn=\" + nonceString);\n })\n\nTrack playback events\n---------------------\n\nLastly, you need to implement various event handlers for your player. For\ntesting purposes, you can attach these to button click events, but in a real\nimplementation, these would be triggered by the appropriate player events:\n\n#### pal.js\n\n /**\n * Informs PAL that an ad click has occurred. How this function is\n * called will vary depending on your ad implementation.\n */\n function sendAdClick() {\n nonceManager?.sendAdClick();\n }\n\n /**\n * Handles the user touching on the video element, passing it to PAL.\n * @param {!TouchEvent|!MouseEvent} touchEvent\n */\n function onVideoTouch(touchEvent) {\n nonceManager?.sendAdTouch(touchEvent);\n }\n\n /** Informs PAL that playback has started. */\n function sendPlaybackStart() {\n nonceManager?.sendPlaybackStart();\n }\n\n /** Informs PAL that playback has ended. */\n function sendPlaybackEnd() {\n nonceManager?.sendPlaybackEnd();\n }\n\nIn your implementation, `sendPlaybackStart` should be called once your video\nplayback session begins. `sendPlaybackEnd` should be called once your video\nplayback session comes to an end. `sendAdClick` should be called each time the\nviewer clicks an ad. `sendAdTouch` should be called on every touch interaction\nwith the player.\n\n(Optional) Send Google Ad Manager signals through third-party ad servers\n------------------------------------------------------------------------\n\nConfigure the third-party ad server's request for Ad Manager.\n| **Note:** If you use multiple third-party solutions---for example, a third-party SSAI server calling another third-party ad server, you need to make sure the PAL SDK's encrypted nonce is forwarded to each third party.\n\nConfigure your third-party ad server to include the nonce in the server's\nrequest to Ad Manager. Here's an example of an ad tag configured inside of the\nthird-party ad server: \n\n 'https://pubads.serverside.net/gampad/ads?givn=%%custom_key_for_google_nonce%%&...'\n\nFor more details, see the [Google Ad Manager Server-side implementation\nguide](//support.google.com/admanager/answer/10668760).\n\nAd Manager looks for `givn=` to identify the nonce value. The third-party ad\nserver needs to support some macro of its own, such as\n`%%custom_key_for_google_nonce%%`, and replace it with the nonce query parameter\nyou provided in the previous step. More information on how to accomplish this\nshould be available in the third-party ad server's documentation.\n\nThat's it! You should now have the nonce parameter propagated from the PAL SDK,\nthrough your intermediary servers, and then to Google Ad Manager. This enables\nbetter monetization through Google Ad Manager."]]