Search in sources :

Example 1 with EventProperties

use of com.microsoft.appcenter.analytics.EventProperties in project mobile-center-sdk-android by Microsoft.

the class EventActivity method send.

@Override
public void send(View view) {
    AnalyticsTransmissionTarget target = getSelectedTarget();
    PersistenceFlag persistenceFlag = PersistenceFlag.values()[mPersistenceFlagSpinner.getSelectedItemPosition()];
    int flags = getFlags(persistenceFlag);
    String name = mName.getText().toString();
    Map<String, String> properties = null;
    EventProperties typedProperties = null;
    if (mProperties.size() > 0) {
        if (onlyStringProperties()) {
            properties = readStringProperties();
        } else {
            typedProperties = new EventProperties();
            for (TypedPropertyFragment fragment : mProperties) {
                fragment.set(typedProperties);
            }
        }
    }
    /* First item is always empty as it's default value which means either AppCenter, one collector or both. */
    for (int i = 0; i < getNumberOfLogs(); i++) {
        boolean useExplicitFlags = persistenceFlag != PersistenceFlag.DEFAULT;
        if (target == null) {
            if (properties != null) {
                if (useExplicitFlags) {
                    Analytics.trackEvent(name, properties, flags);
                } else {
                    Analytics.trackEvent(name, properties);
                }
            } else if (typedProperties != null || useExplicitFlags) {
                if (useExplicitFlags) {
                    Analytics.trackEvent(name, typedProperties, flags);
                } else {
                    Analytics.trackEvent(name, typedProperties);
                }
            } else {
                Analytics.trackEvent(name);
            }
        } else {
            if (properties != null) {
                if (useExplicitFlags) {
                    target.trackEvent(name, properties, flags);
                } else {
                    target.trackEvent(name, properties);
                }
            } else if (typedProperties != null || useExplicitFlags) {
                if (useExplicitFlags) {
                    target.trackEvent(name, typedProperties, flags);
                } else {
                    target.trackEvent(name, typedProperties);
                }
            } else {
                target.trackEvent(name);
            }
        }
    }
}
Also used : AnalyticsTransmissionTarget(com.microsoft.appcenter.analytics.AnalyticsTransmissionTarget) EventProperties(com.microsoft.appcenter.analytics.EventProperties) TypedPropertyFragment(com.microsoft.appcenter.sasquatch.fragments.TypedPropertyFragment)

Example 2 with EventProperties

use of com.microsoft.appcenter.analytics.EventProperties in project mobile-center-sdk-android by Microsoft.

the class EventPropertiesActivity method updatePropertyList.

@SuppressWarnings({ "unchecked", "ConstantConditions" })
private void updatePropertyList() {
    try {
        Field field = getSelectedTarget().getPropertyConfigurator().getClass().getDeclaredField("mEventProperties");
        field.setAccessible(true);
        EventProperties eventProperties;
        try {
            eventProperties = (EventProperties) field.get(getSelectedTarget().getPropertyConfigurator());
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        Method method = eventProperties.getClass().getDeclaredMethod("getProperties");
        method.setAccessible(true);
        Map<String, TypedProperty> properties = (Map<String, TypedProperty>) method.invoke(eventProperties);
        mPropertyListAdapter.mList.clear();
        for (Map.Entry<String, TypedProperty> entry : properties.entrySet()) {
            Object value = entry.getValue().getClass().getMethod("getValue").invoke(entry.getValue());
            mPropertyListAdapter.mList.add(new Pair<>(entry.getKey(), value));
        }
        mListView.setAdapter(mPropertyListAdapter);
        mPropertyListAdapter.notifyDataSetChanged();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : EventProperties(com.microsoft.appcenter.analytics.EventProperties) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) JSONObject(org.json.JSONObject) Map(java.util.Map) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty)

Aggregations

EventProperties (com.microsoft.appcenter.analytics.EventProperties)2 AnalyticsTransmissionTarget (com.microsoft.appcenter.analytics.AnalyticsTransmissionTarget)1 TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)1 TypedPropertyFragment (com.microsoft.appcenter.sasquatch.fragments.TypedPropertyFragment)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1