YZ_NativeAdObject.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import PlatUtils from "./PlatUtils";
  2. import { utils } from "./Utils";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class YZ_NativeAdObject {
  6. _nativeObj: any = null;
  7. _nativeAdData: any = null;
  8. is_reportClick: boolean = false;
  9. is_reportShow: boolean = false;
  10. get data() {
  11. return this._nativeAdData
  12. }
  13. set data(_data: any) {
  14. this._nativeAdData = _data;
  15. }
  16. /**
  17. * 上报原生广告展示
  18. */
  19. reportAdShow() {
  20. if (this._nativeAdData && !this.is_reportShow) {
  21. this.is_reportShow = true;
  22. utils.showLog("上报原生广告展示! adId:", this._nativeAdData.adId);
  23. if (this._nativeObj) {
  24. this._nativeObj.reportAdShow({
  25. adId: this._nativeAdData.adId
  26. });
  27. }
  28. }
  29. }
  30. /**
  31. * 上报原生广告点击
  32. * @param type 1:banner,2:结算广告
  33. */
  34. reportAdClick(type: number = 2) {
  35. this.is_reportClick = true;
  36. if (this._nativeAdData) {
  37. utils.showLog("上报原生广告点击! adId:", this._nativeAdData.adId);
  38. if (this._nativeObj) {
  39. this._nativeObj.reportAdClick({
  40. adId: this._nativeAdData.adId
  41. });
  42. if (type == 2) {
  43. if (PlatUtils.IsOPPO) {
  44. utils.oppoTool.countNativeInserClick();
  45. } else if (PlatUtils.IsVIVO) {
  46. utils.Tool_Vivo.countNativeInserClick();
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }