Customized infeed advertising

When you wish to display in a more flexible way than with simple infeed advertising, it is possible to use a customized infeed advertising function.

Be sure to include a description in implementation so that the user recognizes and understands that the implemented advertising location is for an advertisement.

  • By using the parameter displayedAdvertiser, it is possible to display suitable text in each advertisement.

Loading customized infeed advertising

Create RFPInstreamAdPlacer instance, and call loadAd() to load advertisements. Be sure to set RFPInstreamAdPlacerListener to receive callback from SDK.

public class YourRecyclerActivity extends Activity implements RFPInstreamAdPlacerListener {
    private RFPInstreamAdPlacer adPlacer;
    private AdsAdapter adapter;
    private List<Object> yourContentsItemList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recycler);

        adPlacer = RFP.createInstreamAdPlacer(getActivity().getApplicationContext(), "YOUR_ADSPOT_ID");
        adPlacer.setAdListener(this);
        // Start to load advertisement
        adPlacer.loadAd();
        RecyclerView yourAppRecycleView = findViewById(R.id.recycler);
        // init your app's content list
        initializeyourContentsItemList();
        rfpAdapter = new AdsAdapter(yourContentsItemList, adPlacer);
        yourAppRecycleView.setAdapter(rfpAdapter);

    }

    // When advertising loading is complete
    @Override
    public void onAdsLoaded(List<? extends RFPInstreamInfoModel>items) {
    }
    // When main image loading in advertising View is complete
    @Override
    public void onAdMainImageLoaded(String imageUrl) {
    }
    // When main image loading fails
    @Override
    public void onAdImageLoadedFail(String imageUrl, String errorString) {
    }
    // When advertising loading fails
    @Override
    public void onAdsLoadedFail(String errorString) {
    }
    // When clicking advertising View
    @Override
    public void onAdClicked(String redirectURL) {
    }
}

Parameters used for displaying customized infeed advertising

Also refer to jp.fout.rfp.android.sdk.model.RFPInstreamInfoModel.

Parameter name Description Example
title Title text (20 full-sized characters or less) TestAd
content description/introductory text (40-70 full-sized characters or less) This is text advertising
position advertisement case relative position 3
displayedAdvertiser displayed advertiser name Drinks company A
creative_url banner-type square images url https://example.rfp.fout.jp/image.jpg
creative_width Size of banner image(or video advertisement) (width) 640
creative_height Size of banner image(or video advertisement) (height) 360

Displaying customized infeed advertising

The metadata information of the advertisement is in the RFPInstreamInfoModel, and build the advertisement’s view based on this.

It is necessary to call measureImp and sendClickEvent respectively, when displaying advertisements and clicking advertisements.

class AdsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    RFPInstreamAdPlacer adPlacer;
    List<Object> yourContentsItemList;

    /**
     * @param yourContentsItemList your App's contents list
     * @param adPlacer RFP#createInstreamAdPlacer()'s instance
     */
    AdsAdapter(List<Object> yourContentsItemList, RFPInstreamAdPlacer adPlacer) {
        this.yourContentsItemList = yourContentsItemList;
        this.adPlacer = adPlacer;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // Build app's layout
        View v = inflater.inflate(R.layout.rfp_ad_view, parent, false);
        return new AdViewHolder(v, adPlacer);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RFPInstreamInfoModel adInfo = (RFPInstreamInfoModel) yourContentsItemList.get(position);
        AdViewHolder adHolder = (AdViewHolder) holder;
        adHolder.setData(adInfo);

        // Send impression
        // Based on IAB's guideline, display ads need at least 50% of the advertisement is visible and for at least 1 second(Video ads need at least 2 consecutive seconds)to send impression events.
        // SDK will avoid the duplication of impression sent
        adPlacer.measureImp(adInfo);

    }

    /**
     * Advertisement's ViewHolder
     */
    private static class AdViewHolder extends RecyclerView.ViewHolder {
        RFPInstreamAdPlacer adPlacer;
        RFPInstreamInfoModel adData;

        TextView advertiserName;
        TextView adText;
        ImageView adImage;
        TextView adSponsoredLabel;

        AdViewHolder(View itemView, RFPInstreamAdPlacer placer) {
            super(itemView);

            adPlacer = placer;
            itemView.setOnClickListener(this);
            advertiserName = itemView.findViewById(R.id.advertiser_name);
            adText = itemView.findViewById(R.id.ad_text);
            adImage = itemView.findViewById(R.id.ad_image);
            adSponsoredLabel = itemView.findViewById(R.id.sponsor_name);
        }

        void setData(RFPInstreamInfoModel data) {
            adData = data;
            advertiserName.setText(data.title());
            adText.setText(data.content());

            String displayedAdvertiser = data.displayedAdvertiser();
            if (null != displayedAdvertiser && 0 < displayedAdvertiser.length()) {
                adSponsoredLabel.setText(displayedAdvertiser);
            }

            (new ImageLoader(data.creative_url(), adImage)).execute();
        }

        @Override
        public void onClick(View view) {
            // call RFPInstreamAdPlacer#sendClickEvent() to open advertisement
            adPlacer.sendClickEvent(adData);
        }
    }
}

Support for animated GIF advertising

SDK doesn’t support animated GIF directly, please use Movie and AnimatedImageDrawable for showing animated GIF, or use some third-party libraries like Glide to load animated GIF.

Acquiring the advertising ID

It is possible to acquire the advertising ID with RFPInstreamInfoModel#ad_id().

 static class AdViewHolder {
     // ... ...
     void setData(RFPInstreamInfoModel adData) {
         // ... ...
         String ad_id = adData.ad_id();
         // ... ...
     }
 }