Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable setting global contexts initialising a tracker using remote configuration #575

Open
dss-kenya opened this issue Jan 30, 2023 · 3 comments
Milestone

Comments

@dss-kenya
Copy link

I am not sure if this is more of an issue or a question, and not even sure where i should have raised this, which is why i am doing it here. I am trying to createTracker/setup a tracker with default configurations and also a remote config and even some custom global contexts. however, there are two methods i could access:

public static void setup(@NonNull Context context, @NonNull RemoteConfiguration remoteConfiguration, @Nullable List<ConfigurationBundle> defaultBundles, @Nullable Consumer<Pair<List<String>, ConfigurationState>> onSuccess) {
configurationProvider = new ConfigurationProvider(remoteConfiguration, defaultBundles);
configurationProvider.retrieveConfiguration(context, false, fetchedConfigurationPair -> {
FetchedConfigurationBundle fetchedConfigurationBundle = fetchedConfigurationPair.first;
ConfigurationState configurationState = fetchedConfigurationPair.second;
List<ConfigurationBundle> bundles = fetchedConfigurationBundle.configurationBundle;
List<String> namespaces = createTracker(context, bundles);
if (onSuccess != null) {
onSuccess.accept(new Pair<>(namespaces, configurationState));
}
});

OR

@NonNull
public static TrackerController createTracker(@NonNull Context context, @NonNull String namespace, @NonNull NetworkConfiguration network, @NonNull Configuration... configurations) {
ServiceProvider serviceProvider = serviceProviderInstances.get(namespace);
if (serviceProvider != null) {
List<Configuration> configList = new ArrayList<>(Arrays.asList(configurations));
configList.add(network);
serviceProvider.reset(configList);
} else {
serviceProvider = new ServiceProvider(context, namespace, network, Arrays.asList(configurations));
registerInstance(serviceProvider);
}
return serviceProvider.getOrMakeTrackerController();
}

The problem i face is this:
setUp receives a configurationBundle which is part of the remoteconfiguaration package, this bundle class only accepts for different configurations. There are times when the global config is not even sent when an event is logged using the tracker.. In order to avoid this, it is necessary to supply a GlobalContextConfiguration which i can do when i call createTracker. This in turn leads to another issue, where we can set the global context configuration, but we cannot set the remote config, since createTracker only takes network config.

Can anyone please suggest what i should do or how best i can use both remote config, default configs and even global config without losing data when logging?

@matus-tomlein
Copy link
Contributor

This is not just a question, but a valid issue! It is currently not possible to supply a global contexts configuration when initialising a tracker using remote configuration.

You should not be using the Snowplow.createTracker() function in case you want to set up a tracker using remote configuration. When using remote config, you can only use the Snowplow.setup() function. Currently this doesn't let you pass a global contexts configuration, but we will make it the goal of this issue to enable that.

One workaround that you may try is to add global contexts later on, after the tracker is created. In that case, you would do something like:

Snowplow.setup(getApplicationContext(), remoteConfig, null, configurationPair -> {
     Snowplow.getDefaultTracker().getGlobalContexts().add(...)
});

Thanks for reporting the issue!

@matus-tomlein matus-tomlein changed the title [Question] How do we set up globalConfig and remoteConfig ? Enable setting global contexts initialising a tracker using remote configuration Jan 30, 2023
@dss-kenya
Copy link
Author

dss-kenya commented Jan 30, 2023

Thank you for the prompt reply and for the workaround, i will try it and let you know if i still miss logging in some cases.

@dss-kenya
Copy link
Author

dss-kenya commented Jan 30, 2023

headups, i still face situations where i am missing data when logging, i tried the workaround and it also returns a boolean true when contexts are being added. Is there anything else i might be missing?

EDIT: Works fine now, just changed how i was attaching the contexts.
cc: @matus-tomlein

@mscwilson mscwilson added this to the 6.1.0 milestone Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants