React Native
همه فرمتها، نصب و نمونه کامل اتصال مستقیم.
سه قدم تا اولین تبلیغ React Native
- رسانه و جایگاه همان فرمت را ثبت و تأیید کنید.
- بسته همین پلتفرم را نصب کنید.
- شناسه UNT_ مثال را با شناسه جایگاه خود جایگزین کنید.
نشانی HTTPS در مثال، سرور خود دیدنکس است. در حالت مستقیم، JWT، کلید خصوصی و ورود کاربر لازم نیست. Android، iOS، Unity و B4A شناسه بسته را از خود اپ میخوانند؛ Flutter نیز در initialize جدید، شناسه بسته را محلی میخواند؛ ورود دستی در روش سازگار قدیمی ممکن است. تغییر دامنه دیدنکس فقط به تغییر همین نشانی در تنظیم اپ نیاز دارد.
۱. نصب و تنظیم اولیه
بسته محلی didnex-react-native-ads را نصب و react-native-webview و expo-secure-store را مطابق نسخه میزبان اضافه کنید. نمونه کامل App.tsx شامل ذخیره امن و همه فرمتهاست. در پنل رشد پیشرفته پروژه Expo کامل با شناسههای خودتان دریافت کنید.
نمونه: Expo58، RN0.88، React19.3، WebView14، Node22.13+/24.3+. Android و iOS؛ ساخت و امضا با ابزار بومی میزبان.
npm install ./didnex-react-native
npx expo install react-native-webview expo-secure-storeراهاندازی یکباره تبلیغ و پوش
نمونه کوتاه زیر فقط تنظیم اولیه است؛ callback و ظرف نمایش را در مثال کامل همین صفحه ببینید. init اجازه اعلان نمیگیرد و عضویت خودکار ندارد. یک کلاینت را برای عمر اپ نگه دارید و همان را برای تبلیغ و پوش استفاده کنید.
const placementId = "PASTE_YOUR_PLACEMENT_ID_HERE";
import {initializeDidnex} from 'didnex-react-native-ads';
const client = initializeDidnex({
origin:'https://didnex.com',
packageName:'com.company.app', platform:'android'
});
// Pass this same client to <DidnexAd client={client} unitId={placementId} />
const push = client.createPush(placementId, async message => false);
// Choose the actual android/ios platform and store installation tokens securely.اندازه ثابت جایگاه
اندازه از slot جایگاه تعیین میشود؛ تصویر و ویدیو با contain داخل همان کادرند. ابعاد فایل یا آمادهشدن ویدیو، اندازه بیرونی را عوض نمیکند. noFill و خطا کادر را جمع میکنند. در Unity و Godot مستطیل میزبان را مطابق پروفایل انتخاب کنید.
| پروفایل دیدنکس | اندازه مرجع | نوار ثابت زیر رسانه |
|---|---|---|
| بنر استاندارد ۳۲۰ × ۵۰ | 320 × 50 | ندارد |
| بنر بزرگ ۳۲۰ × ۱۰۰ | 320 × 100 | ندارد |
| بنر مستطیل ۳۰۰ × ۲۵۰ | 300 × 250 | ندارد |
| بنر عریض ۷۲۸ × ۹۰ | 728 × 90 | ندارد |
| بنر تطبیقی با نسبت ۳۲۰ × ۵۰ | 320 × 50 | ندارد |
| همسان افقی ۱۶:۹ + نوار ثابت | 640 × 360 | 84 پیکسل منطقی |
| همسان مربع + نوار ثابت | 600 × 600 | 84 پیکسل منطقی |
| ویدیوی همسان ۱۶:۹ + نوار ثابت | 640 × 360 | 84 پیکسل منطقی |
| ویدیوی درون محتوا ۱۶:۹ | 640 × 360 | ندارد |
| کاروسل ۱۶:۹ با نوار ثابت | 640 × 360 | 84 پیکسل منطقی |
| نظرسنجی در کادر ثابت | 320 × 300 | 84 پیکسل منطقی |
| کارت صوتی ثابت | 320 × 96 | ندارد |
| تمامصفحه با حاشیه امن | 360 × 640 | 84 پیکسل منطقی |
| تمامصفحه با حاشیه امن | 360 × 640 | 84 پیکسل منطقی |
| تمامصفحه با حاشیه امن | 360 × 640 | 84 پیکسل منطقی |
| تمامصفحه با حاشیه امن | 360 × 640 | 84 پیکسل منطقی |
| تمامصفحه با حاشیه امن | 360 × 640 | 84 پیکسل منطقی |
اینها پروفایل محصول دیدنکساند؛ گواهی استاندارد یا یک اندازه پیکسلی جهانی برای همه فرمتها نیستند. حداقل وضوح در فرم کمپین کنترل میشود. برای فعالشدن renderer جدید در اپ نصبشده، یک بار SDK را بهروزرسانی کنید.
فونت و ظاهر مشترک
ظاهر کارت در هر دو روش مستقیم و پراکسی از پاسخ همان تبلیغ خوانده میشود. مدیر در تنظیمات ← ظاهر تبلیغ و SDK، رنگ، زمینه، فونت، گردی کارت، جای نشان و پخش خودکار ویدیوی معمولی را تعیین میکند. ابتدا یکبار SDK و اپ را بهروزرسانی کنید؛ سپس تغییرات پشتیبانیشده در درخواست بعدی تبلیغ اعمال میشوند. فونت Noto Sans Arabic فارسی و لوگو از سرور خود دیدنکس کش میشوند؛ خطای این داراییهای اختیاری باعث noFill یا خطای تبلیغ نمیشود. Unity برای UGUI یک فونت کوچک فارسی همراه و شکلدهی حروف در مرز نمایش دارد. سرور کد اجرایی جدید به اپ نمیفرستد.
ویدیوی معمولی هنگام دیدهشدن خودکار و بیصداست؛ صوت و جایزه با انتخاب کاربر شروع میشوند. دامنه دیدنکس را در font-src سیاست CSP وب مجاز کنید.
۲. Manifest و مجوزهای لازم
قطعه زیر را با فایل موجود ادغام کنید. INTERNET باید در Manifest اصلی نسخه Release هم باشد. تبلیغ پایه به مجوز مکان، اعلان، حافظه یا شناسه تبلیغاتی نیاز ندارد.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"><uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><!-- POST_NOTIFICATIONS only for opt-in background push Android13+. --></manifest>در iOS فایل PrivacyInfo.xcprivacy بسته را به منابع Target اضافه کنید؛ HTTPS به غیرفعالکردن ATS نیاز ندارد. UIBackgroundModes فقط برای پوش پسزمینه اختیاری است. در Unity دسترسی اینترنت Player Settings را روی Require قرار دهید.
بازکردن جایگاه و راهنمای قدمبهقدم اتصال — در پنل، نمونه با شناسه و بستهٔ رسانهٔ شما ساخته میشود؛ تست تا دریافت گزارش همان جلسه ادامه دارد.
۳. مثال کامل هر فرمت
هر شناسه جایگاه فقط یک فرمت دارد؛ فرمت باید با نوع رسانه و سیاستهای پنل سازگار باشد. مثال کامل همان فرمت را انتخاب کنید. تمامصفحه فقط در نقطه طبیعی تجربه کاربر نمایش داده شود. ویدیوی معمولی خودکار و بیصداست؛ صوت و جایزه با اقدام کاربر شروع میشوند.
بنر · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'UNT_BANNER','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('banner'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="banner").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
بنر تطبیقی · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'UNT_ADAPTIVE_BANNER','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('adaptive_banner'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="adaptive_banner").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
همسان · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'UNT_NATIVE','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('native'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="native").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
ویدیوی همسان · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'UNT_NATIVE_VIDEO','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('native_video'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="native_video").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
ویدیوی درون محتوا · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'UNT_VIDEO','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('video'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="video").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
بینابینی · تمامصفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'UNT_INTERSTITIAL','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('interstitial'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="interstitial").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
ویدیوی جایزهدار · جایزهدار
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'UNT_REWARDED','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('rewarded'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="rewarded").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
بینابینی جایزهدار · جایزهدار
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'UNT_REWARDED_INTERSTITIAL','app_open':'','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('rewarded_interstitial'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="rewarded_interstitial").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
آغاز اپ · تمامصفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'UNT_APP_OPEN','playable':'','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('app_open'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="app_open").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
بازی تعاملی · تمامصفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'UNT_PLAYABLE','audio':'','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('playable'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="playable").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
صوتی · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'UNT_AUDIO','carousel':'','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('audio'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="audio").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
کاروسلی · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'UNT_CAROUSEL','poll':''};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('carousel'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="carousel").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
نظرسنجی · درون صفحه
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from 'didnex-react-native-ads';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'https://didnex.com',packageName:'com.company.app',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'','adaptive_banner':'','native':'','native_video':'','video':'','interstitial':'','rewarded':'','rewarded_interstitial':'','app_open':'','playable':'','audio':'','carousel':'','poll':'UNT_POLL'};
const diagnosticToken="".trim() || undefined;
export default function App(){const [format,setFormat]=useState<AdFormat>('poll'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.filter(f=>f==="poll").map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} diagnosticToken={diagnosticToken} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
۴. مثال کامل با مدیریت خطا
این مثال عیناً از فایل sdk/react-native/examples/App.tsx داخل بسته ساخته میشود. نام package نمونه، شناسههای UNT_ و ظرف نمایش را با اپ خود هماهنگ کنید. برای بنر و تمامصفحه از نمونه جدا استفاده کنید.
نمایش مثال کامل React Native
import React,{useState} from 'react';
import {Platform,SafeAreaView,ScrollView,Text,Pressable} from 'react-native';
import * as SecureStore from 'expo-secure-store';
import {createDidnexClient,DidnexAd,DidnexPanel,formats,type AdFormat} from '../src';
const key=(value:string)=>'didnex_'+Array.from(new TextEncoder().encode(value),b=>b.toString(16).padStart(2,'0')).join('');
// IDs are public identifiers. Never place administrator credentials in the app.
const client=createDidnexClient({origin:'__DIDNEX_ORIGIN__',packageName:'__DIDNEX_PACKAGE__',platform:Platform.OS==='ios'?'ios':'android',storage:{get:k=>SecureStore.getItemAsync(key(k)),set:(k,v)=>SecureStore.setItemAsync(key(k),v),remove:k=>SecureStore.deleteItemAsync(key(k))}});
const units:Record<AdFormat,string>={'banner':'__DIDNEX_UNIT_BANNER__','adaptive_banner':'__DIDNEX_UNIT_ADAPTIVE_BANNER__','native':'__DIDNEX_UNIT_NATIVE__','native_video':'__DIDNEX_UNIT_NATIVE_VIDEO__','video':'__DIDNEX_UNIT_VIDEO__','interstitial':'__DIDNEX_UNIT_INTERSTITIAL__','rewarded':'__DIDNEX_UNIT_REWARDED__','rewarded_interstitial':'__DIDNEX_UNIT_REWARDED_INTERSTITIAL__','app_open':'__DIDNEX_UNIT_APP_OPEN__','playable':'__DIDNEX_UNIT_PLAYABLE__','audio':'__DIDNEX_UNIT_AUDIO__','carousel':'__DIDNEX_UNIT_CAROUSEL__','poll':'__DIDNEX_UNIT_POLL__'};
export default function App(){const [format,setFormat]=useState<AdFormat>('banner'),[screen,setScreen]=useState<'preferences'|'messages'|'offers'|null>(null),[notice,setNotice]=useState('');const unit=units[format];return <SafeAreaView style={{flex:1}}><ScrollView contentContainerStyle={{padding:20,gap:12}}><Text>Didnex · 1</Text>{formats.map(f=><Pressable key={f} onPress={()=>{setScreen(null);setFormat(f);}}><Text>{f}</Text></Pressable>)}<Text>{notice}</Text>{unit?<DidnexAd key={format} client={client} unitId={unit} format={format} onError={setNotice} onReward={receipt=>setNotice('Verified grant: '+String(receipt.grantId))}/>:<Text>Create an active {format} unit in the publisher panel first.</Text>}{(['preferences','messages','offers'] as const).map(s=><Pressable key={s} onPress={()=>setScreen(s)}><Text>{s}</Text></Pressable>)}{screen&&unit?<DidnexPanel key={screen} client={client} unitId={unit} screen={screen}/>:null}</ScrollView></SafeAreaView>;}
۵. نبود تبلیغ، قطعی شبکه و چرخه عمر
آغاز اپ را منتظر تبلیغ نگه ندارید. noFill وضعیت عادی است؛ فضای تبلیغ را مخفی کنید و اپ ادامه یابد. درخواست پشت سر هم و retry بیوقفه انجام ندهید. هنگام حذف صفحه، handle یا view را مطابق مثال ببندید. در تب پنهان یا پوشش سفارشی، active را false کنید. نمایش خودکار روی هر resume مناسب نیست.
۶. جایزه، کیف و پوش
جایزه فقط پس از انتخاب کاربر، تماشای کامل و رسید verified و applied سرور معتبر است. callback یعنی جایزه پیشتر در کیف نصب دیدنکس ثبت شده؛ دوباره به موجودی اضافه نکنید. برای مصرف، externalId را پیش از ارسال ذخیره و در retry ثابت نگه دارید. کیف نصب، حساب قابل بازیابی چنددستگاهی نیست.
Inbox بدون Firebase و در اپ فعال کار میکند. پوش پسزمینه به رضایت کاربر، مجوز سیستمعامل و اتصال FCM/APNs/Web Push نیاز دارد؛ فعالکردن تبلیغ به این تنظیمها وابسته نیست. همه ۱۳ فرمت اتصال مستقیم دارند؛ React Native و Godot فعلاً مستقیم هستند و شش SDK اصلی پراکسی اختیاری هم دارند.
۷. آزمون و رفع خطا
diagnosticToken پنل، با فایل واقعی متناسب با فرمت (تصویر، ویدیو، صوت یا بازی) تست بدون هزینه و جایزه میدهد؛ تأیید تحویل مالی نیست. برای تبلیغ واقعی، کمپین سازگار با بودجه و رسانه فعال لازم است. در خطای package، پسوند flavor خروجی را با رسانه تطبیق دهید؛ در وب Origin دقیق و HTTPS را بررسی کنید. خطای سرویس را با موفقیت مالی یا جایزه محلی جایگزین نکنید.
پیش از انتشار اپ، ساخت Release، قطع شبکه، DNS نامعتبر، پاسخ خراب، خروج صفحه وسط درخواست، پسزمینه و تکرار claim را روی دستگاه هدف بررسی کنید. مسیر ساخت تکرارپذیر و تستهای هر SDK همراه سورس هستند.
قابلیتهای SDK جدید و عیبیاب داخل اپ
نسخه نمایشی این انتشار ۱ است؛ شماره فنی و هش هر بسته در مرکز SDK درج شده است. هر ۱۱ فرمت در اتصال مستقیم و سرور اختیاری پشتیبانی میشوند؛ playable با helper بینابینی نمایش داده میشود و نیازمند SDK جدید است. در «لابراتوار تبلیغ»، بازی را بسازید و کمپین/جایگاه با فرمت playable انتخاب کنید. قالبهای همان بازی در Flutter/Unity بومی رسم میشوند؛ وب و Kotlin/Swift/B4A از محیط HTML5 محدود استفاده میکنند.
برای عیبیاب، از پنل ناشر توکن تست جایگاه بگیرید و همان درخواست تست را اجرا کنید. در Flutter حالت debug، Android اپ debuggable، Swift ساخت DEBUG و Unity ساخت Development نیز مجازند. گزارش فقط محلی و محدود به ۸۰ رخداد، زمان، خطا، نوع رسانه و کیفیت است؛ کلید، JWT، URL امضاشده و شناسه مخاطب ثبت نمیشود. خروجی کپی را خودتان برای پشتیبانی میفرستید.
await DidnexAds.diagnose(document.querySelector('#slot'), 'UNT_ID', diagnosticToken);
DidnexAds.showInspector();خروجیهای ویدیوی تطبیقی بهطور خودکار از mediaSources انتخاب میشوند. حالت کممصرف/شبکه موبایل کیفیت پایین، Wi-Fi یا شبکه سریع کیفیت بالاتر و شبکه نامشخص کیفیت میانی میگیرد. اجازه ACCESS_NETWORK_STATE در Android برای تشخیص شبکه لازم است؛ در نبود دسترسی، انتخاب محافظهکارانه انجام میشود. رویداد بارگذاری، نمایش قابل مشاهده، پیشرفت ویدیو و تأیید جایزه همچنان از مسیر امضاشده میگذرند؛ عیبیاب درآمد ایجاد نمیکند.
ابزارهای ساخت موبایل و دستگاه واقعی در محیط انتشار این سورس در دسترس نبودند. آزمون قرارداد سرور، رمزنگاری، تولید رسانه و پنل انجام شده؛ پیش از انتشار اپ، ساخت SDK در Flutter/Xcode/Android Studio/Unity/B4A و آزمون دستگاه را انجام دهید. بستهها روی pub.dev یا فروشگاهها منتشر نشدهاند.