trackViewability()

From Engineering Client Portal

Revision as of 20:52, 5 October 2022 by NickParrucci (talk | contribs) (Created page with "{{Breadcrumb|}} {{Breadcrumb|Digital}} {{Breadcrumb|Android SDK API Reference}} {{CurrentBreadcrumb}} Category:Digital Category:Android SDK API Reference Viewability...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Engineering Portal / Digital / Android SDK API Reference / trackViewability()

Viewability support requires additional parameters to be provided from player applications to the SDK. In order to provide those parameters and to start the viewability measurement trackViewability method is added to the public SDK API.

Syntax


void  trackViewability(JSONObject);

Calling trackViewability for a player view


String targetViewTag = targetView.getTag().toString();
String activityObj = MainActivity.this;
JSONArray friendlyTags = new JSONArray();
friendlyTags.put("friendlyViewTag1");
friendlyTags.put("friendlyViewTag2");

JSONObject json = new JSONObject();
json.put("viewContainer", activityObj);
json.put("viewTag", targetViewTag);
json.put("friendlyObstructions", friendlyTags);
sdkInstance.trackViewability(json);

Setting tag for a player view in layout xml


<SurfaceView
   android:id="@+id/playerView"
   android:tag="playerViewTag"           
   android:layout_width="match_parent"
   android:layout_height="match_parent"
/>

Setting tag for a player view in Activity/Fragment


mPlayerView = (SurfaceView) findViewById(R.id.playerView);
mPlayerView.setTag("playerViewTag");

Input Parameters

Parameter Description
data JSONObject object with the following objects and keys:
viewTag (mandatory) value of String type, tag identifier for the target player view object. This tag can be assigned for the player view either programmatically or in the layout xml, as explained in above section.
viewContainer (mandatory) Reference to the activity object. It is needed to identify and search the target player view in current visible screen. This parameter can not be nil. This should be the current activity object where target view is loaded. If the player view is rendered in a fragment, please provide the parent activity reference of the fragment.
friendlyObstructions (optional) an array of tags of the views which should be ignored during the intersection ratio calculation. Those are views like loading activity indicator, player controls, view with a watermark, etc. which are displayed in front of the target view, but should not reduce the viewability intersection ratio. The tags of such should be wrapped into the String objects before adding into the array. This parameter is nullable, empty array is also accepted.

PlayerScreen ViewContainer-ViewTag-FriendlyViews.png

Output Parameters

Output Parameters (Return value) Description
Void

Notes

If incorrect view tag is provided, SDK will not be able to measure viewability metrics. Viewability engine tries to find a view for the provided tag during 15 seconds and if it is not found it goes to inactive state. In order to restart the viewability engine it is required to call trackViewability with a proper tag again.