एक नॉनस जनरेट करना
"नॉन्स" एक एन्क्रिप्ट किया गया स्ट्रिंग होता है. इसे PAL, NonceLoader का इस्तेमाल करके जनरेट करता है.
PAL SDK टूल के लिए, हर नए स्ट्रीम अनुरोध के साथ नया नॉनस भेजना ज़रूरी है. हालांकि, एक ही स्ट्रीम में विज्ञापन के कई अनुरोधों के लिए, नॉनस का फिर से इस्तेमाल किया जा सकता है. PAL का इस्तेमाल करके नॉनस जनरेट करने वाला सैंपल ऐप्लिकेशन देखने के लिए, GitHub से HTML5 का उदाहरण डाउनलोड करें.
PAL SDK का इस्तेमाल करके, नॉनस जनरेट करने के लिए, एक एचटीएमएल फ़ाइल बनाएं और इसमें यह कोड जोड़ें:
pal.html
<html>
<head></head>
<body>
<div id="placeholder-video"></div>
<button id="generate-nonce">Generate Nonce</button>
<script src="//imasdk.googleapis.com/pal/sdkloader/pal.js"></script>
<script src="pal.js"></script>
</body>
</html>
इसके बाद, एक JavaScript फ़ाइल बनाएं और इसमें यह कोड जोड़ें:
pal.js
let videoElement;
let nonceLoader;
let managerPromise;
let nonceManager;
let playbackStarted = false;
/**
* Initializes the PAL loader.
*/
function init() {
const videoElement = document.getElementById('placeholder-video');
videoElement.addEventListener('mousedown', (e) => void onVideoTouch(e));
videoElement.addEventListener('touchstart', (e) => void onVideoTouch(e));
videoElement.addEventListener('play', () => {
if (!playbackStarted) {
sendPlaybackStart();
playbackStarted = true;
}
});
videoElement.addEventListener('ended', () => void sendPlaybackEnd());
videoElement.addEventListener('error', () => {
console.log("Video error: " + videoElement.error.message);
sendPlaybackEnd();
});
document.getElementById('generate-nonce')
.addEventListener('click', generateNonce);
// PAL automatically determines whether limited ads apply based on the TCF data
// found on the page. You can optionally use the `forceLimitedAds` parameter
// to manually enable limited ads regardless of the TCF data.
const consentSettings = new goog.pal.ConsentSettings();
nonceLoader = new goog.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.
*/
function generateNonce() {
const request = new goog.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.1
request.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();
विज्ञापन दिखाने के अनुरोध में अपना नॉन्स अटैच करें
जनरेट किए गए नॉन्स का इस्तेमाल करने के लिए, विज्ञापन अनुरोध करने से पहले अपने विज्ञापन टैग में givn पैरामीटर और नॉन्स वैल्यू जोड़ें.
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
*/
const DEFAULT_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);
})
अगर Google से विज्ञापनों का अनुरोध किया जा रहा है और उन्हें दिखाया जा रहा है, तो आपको AdChoices आइकॉन और ओवरले दिखाना होगा. वीएएसटी रिस्पॉन्स को पार्स करने और आइकॉन रेंडर करने के बारे में ज़्यादा जानने के लिए, AdChoices आइकॉन और ओवरले देखें.
वीडियो चलाने से जुड़े इवेंट ट्रैक करना
आखिर में, आपको अपने प्लेयर के लिए अलग-अलग इवेंट हैंडलर लागू करने होंगे. जांच के लिए, इन्हें बटन क्लिक इवेंट से जोड़ा जा सकता है. हालांकि, असल में लागू करने के दौरान, इन्हें प्लेयर के सही इवेंट से ट्रिगर किया जाएगा:
pal.js
/**
* Informs PAL that an ad click has occurred. How this function is
* called will vary depending on your ad implementation.
*/
function sendAdClick() {
nonceManager?.sendAdClick();
}
/**
* Handles the user touching on the video element, passing it to PAL.
* @param {!TouchEvent|!MouseEvent} touchEvent
*/
function onVideoTouch(touchEvent) {
nonceManager?.sendAdTouch(touchEvent);
}
/** Informs PAL that playback has started. */
function sendPlaybackStart() {
nonceManager?.sendPlaybackStart();
}
/** Informs PAL that playback has ended. */
function sendPlaybackEnd() {
nonceManager?.sendPlaybackEnd();
}
लागू करने के दौरान, वीडियो प्लेबैक सेशन शुरू होने के बाद sendPlaybackStart को कॉल किया जाना चाहिए. वीडियो चलाने का सेशन खत्म होने के बाद, sendPlaybackEnd को एक बार कॉल किया जाना चाहिए. sendAdClick को हर बार तब कॉल किया जाना चाहिए, जब दर्शक किसी विज्ञापन पर क्लिक करे. sendAdTouch को प्लेयर के साथ हर टच इंटरैक्शन पर कॉल किया जाना चाहिए.
(ज़रूरी नहीं) तीसरे पक्ष के विज्ञापन सर्वर के ज़रिए, Google Ad Manager के सिग्नल भेजना
Ad Manager के लिए, तीसरे पक्ष के विज्ञापन सर्वर के अनुरोध को कॉन्फ़िगर करें.
Ad Manager को सर्वर के अनुरोध में नॉनस शामिल करने के लिए, तीसरे पक्ष के विज्ञापन सर्वर को कॉन्फ़िगर करें. यहां तीसरे पक्ष के विज्ञापन सर्वर में कॉन्फ़िगर किए गए विज्ञापन टैग का उदाहरण दिया गया है:
'https://pubads.serverside.net/gampad/ads?givn=%%custom_key_for_google_nonce%%&...'
ज़्यादा जानकारी के लिए, Google Ad Manager के सर्वर-साइड इंटिग्रेशन से जुड़ी गाइड देखें.
Ad Manager, नॉन्स वैल्यू की पहचान करने के लिए givn= को खोजता है. तीसरे पक्ष के विज्ञापन सर्वर को अपने कुछ मैक्रो का इस्तेमाल करना होगा. जैसे, %%custom_key_for_google_nonce%%. साथ ही, इसे पिछले चरण में दिए गए नॉन्स क्वेरी पैरामीटर से बदलना होगा. इसे पूरा करने के तरीके के बारे में ज़्यादा जानकारी, तीसरे पक्ष के विज्ञापन सर्वर के दस्तावेज़ में उपलब्ध होनी चाहिए.
हो गया! अब आपके पास PAL SDK से, मध्यस्थ सर्वर के ज़रिए, और फिर Google Ad Manager को भेजा गया नॉन्स पैरामीटर होना चाहिए. इससे Google Ad Manager के ज़रिए बेहतर तरीके से कमाई की जा सकती है.