Enhance `personalise` call to (optionally) prefill signals dictionary
Since we have a lot (if not all) signals at our disposal already (lot's of these come from the tracking component), we can simplify the call to personalise
by allowing the user to either leave out the signals
parameter, or use it to overwrite signals that we set by deriving them from the tracking component.
public void personalise(String campaign, Map<String, Object> signals, int limit, String abVariantLabel, final PrimedCallback callback) {
Map<String, Object> system_signals = new HashMap();
system_signals.put(self.did); // this is for the moment the only signal we'll add'
// 'magic' merge function, to be implemented or sourced from some lib
// the thing that matters is that user-defined signals (the ones passed
// as a parameter to the `personalise` method) should 'overwrite'
// signals present in the all_signals Map (by key)
all_signals = MapUtils.merge(signals, system_signals)
String signalsString = URLEncoder.encode(this.toJSONString(all_signals));
...
So, if the user provided no signals: we ‘backfill’ the signals dictionary with just the did
property:
user provides no signals, so we default to an empty dictionary:
{}
becomes:
{did: '...'}
we do the same if the user does provide signals:
{device: 'iphone'}
becomes {device: 'iphone', did: '...'}
the only thing to keep in mind is, if the user provides a signals dictionary ánd it happens to already contain a value for did
, we leave it as is:
{did: '...'}
simply stays {did: '...'}
We'll start by simply adding the did
(which is also the most important one), but we'll gradually be adding more.
Note: this only applies if the developer used the PrimedTracker entrypoint