How to create a custom user property for firebase? - android

The help section on the firebase console says that
Firebase app can have up to 25 uniquely named user properties (case-sensitive). You should use properties for non-variable attributes, such as “handedness=right”, “spender=true”.
In the firebase documentation a property is said be to set this way
mFirebaseAnalytics.setUserProperty("favorite_food", mFavoriteFood);
Does this mean that for every user property named k and having a value v, we need to create a user property in the console as "k=v" and set it in the code by setUserProperty(k,v)? So, for a user property called "favorite_food" having the possible values as "pasta" and "pizza", one needs to create two new user properties in the console as "favorite_food=pasta" and "favorite_food=pizza" and set it by, say, setUserProperty("favorite_food","pasta")?

For every User Property named k, you need to register an entry in the "User Properties" tab in Firebase Analytics. For every user with User Property value k=v, you need to call setUserProperty(k,v).
After calling setUserProperty(k,v) (and after logging some events), you will be able to filter your Analytics reports by applying a User Property filter for k=v (favorite_food=pizza) .

Creating an entry for User Property k in the console will allow you to
filter based on k=v0, k=v1, ... for all valid values of k.

Related

Why does .event.set("fieldName", ObjectValue) not storing any data in Google Calendar API android?

I successfully intergarted Google Calendar API. I'm able to do CRUD. But now because of some requirements, I want to send some unique id to each events while creating from android app. For that I found one method called .set() this is a key value pair.
Event event = new Event()
.set("appointment_id", 55475)
.setSummary(summary)
.setLocation(location)
.setDescription(des);
But while fetching, I'm getting all data except event.get("appointment_id")
Why, even it is setting also. [If I'm doing here before executing insert like this: evetn.get("appointment_id"), I'm getting value, because this is locally I'm chocking]
I checked through debugging as well. See below:
But, I'm not getting when I'm fetching all events from Google calendar:
List<Event> items = events.getItems();
You are using the set method, but this is just an override of the com.google.api.client.json.GenericJson class, I believe this will only add this key-value to the final JSON which will be ignored by the API (as it is not an expected field).
Sincerely I don't know what is the point on creating a custom id when there is one directly integrated in calendar.
If you take a look at the insert method you can see that there is one field called id:
Opaque identifier of the event. When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules:
characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938
the length of the ID must be between 5 and 1024 characters
the ID must be unique per calendar
Also in the same description for the field:
If you do not specify an ID, it will be automatically generated by the server.
My point being that if you need unique ID for events in calendar there is a built in method that will create them for you. And even if you need to supply your own id's you can do so informing this field.
Let me suggest you the official guide on event creation in which there is a more detailed view on the option you can take creating an Event.
Also look at the documentation for setId as this is the method you should be using instead of set.
Example:
Event event = new Event()
.setId("55475") // This has to be type String
.setSummary(summary)
.setLocation(location)
.setDescription(des);

Copy data from one child node into another Firebase

I am working on an Android application where there are two types of user. I differentiate them into the system by using the field UserType. I have a requirement where I have to copy data from one child node into another. I am using Firebase for my backend. I have gone through other answers but this requirement is unique in a way that, I want to copy data only on a particular node. Attaching the Firebase database structure
In this structure, if you can see I have expanded 2 child nodes of "users". One of the child has userType as Standard User and other child has userType as Guardian User.
1) I want to copy the "fullNameGuardian" child alone from the user with key starting with "L4bTr6q" to the user with key starting with "dC9Mq"
2) I want to copy the "standardEmail" child alone from the user with key starting with "dC9Mq" to user with key starting with "L4bTr6q".
And everytime I add a new user, the user can be with one of the userType "Standard User" or "Guardian User". So is there a possibility like I do it for every new user?
I am having difficulties figuring out how to do this. Any help is appreciated. Thanks a lot in advance.
I think you could save the other structure when you save the first one. For instance,
Save - node1/child
Update - node2/child
//and so on
Another way is using Firebase functions(Real database triggers) in order to automatically do something after something else had happened. Check it out.

How to correctly nest data and write to Firebase

I have some Edittext that allows the user to enter data:
AppName
Date
Title
Quantity
User
I started a new Firebase project and it is currently a blank slate.
I am setting up my Firebase instance like this:
private DatabaseReference mDatabase;
mDatabase = FirebaseDatabase.getInstance().getReferenceFromUrl("https://myapp.firebase.io");
How I want it is everytime a new adding occurs, I would like to add it like this (AppName is the common ground for all entry):
AppName
Date
Title
Quantity
User
Date
Title
Quantity
User
...
...
AppName
Date
Title
Quantity
User
Date
Title
Quantity
User
...
...
How can I do the following:
The first time it is added, the AppName will be the parent node, and
anytime after Firebase should check to see if the parent node exist
and is the same and add it to that, otherwise create a new parent node
and add the children node to the new parent node.
I currently have my auth set up like this:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
I had to change to true for my app to write to Firebase.
How can I:
Not register the user but only allow the app to able to write to
Firebase.
EDIT:
I am doing the following:
mDatabase.child("AppName").setValue(etName.getText().toString());
mDatabase.child("AppName").child("Date").setValue(etDate.getText().toString());
mDatabase.child("AppName").child("Title").setValue(etQuantity.getText().toString());
mDatabase.child("AppName").child("Quantity").setValue(User.getText().toString());
mDatabase.child("AppName").child("User").setValue(etUser.getText().toString());
Instead of adding, it is overwriting the previous entry. How can I append.
If I understood you, you need that not registered users could edit your database on Firebase and how to know If you added an ID.
First of all, as Ishan Fernando said, If you add data with the same id, this data will be overwrited, and using the push method, Firebase will create an unic ID to add you data
Read this: https://firebase.google.com/docs/database/android/read-and-write?hl=en
This Gist, thanks to the user realgt, could help you to know if the Appname exists or not: https://gist.github.com/anantn/4323949#gistcomment-998628
This will get all your data and you could check if you need add it or not
And, if you don't want to register users, but you need them to write the database, I think that you need to register them as anonymous users:
https://firebase.google.com/docs/auth/android/anonymous-auth
Firebase needs registered users (using social networks, email o anonymously) to modify it, so try the anonymous method. The problem is when the user get out of your app, this user will keep registered on your database. So, I recommend you, (Please, correct me if I'm wrong) to erase the user when onStop starts and create it again when onReady starts.
I hope it helps.

Firebase Analytic Search_Term Param value not showing

I want to log user search event to Firebase but the Search_Term param value in the Search event doesn't show up in the dashboard. Here my code:
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.SEARCH_TERM, searchText);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SEARCH, bundle);
I have tried to log different event with other param and the param value show up in dashboard correctly!
How can I fix this? Thank you
Currently the search data doesn't appear in the Firebase Analytics dashboard.
Your logging seems indeed correct. To see the data you can use Google BigQuery.
One thing you should do is to ensure that searchText is 36 characters or less, otherwise data will just appear as empty in Firebase (and BigQuery).
In general when struggling with data not appearing one should ensure that the logged events follows the possible combinations of events/parameters as described in https://support.google.com/firebase/answer/6317498 . Also notice that the Firebase Console doesn't show the data instantly after being logged (give it at least 30 minutes).
Update:
Firebase Analytics have later increased the maximum length of event names and parameter name to 40 characters, and the maximum length of string parameter values to 100 characters: https://firebase.google.com/support/release-notes/android#wzxhzdk4version_100_-_november_21_2016wzxhzdk5

Save to Android Pay: how to generate 2 unique ID's per object

I'm a real rookie with Android and especially 'Save to Android Pay' API. I'm following the Google's Guide and Google's Sample, in order to implement my own offer class and "Save to Android" button.
According to the tutorial, for every type of offer card I'm creating, I need one Offer Class, and for every user who will save the card to his Android Pay app, a new object will be generated. So Let's say my card has the following fields:
Headline
Logo
Card ID#
and in addition, every user has 2 unique fields:
User ID#
User ID2#
I know when and how to pass the first 3 fields of data but I'm not sure where and how to pass the last 2 fields. I'm implementing the "Save to Android" button on a website (exactly like the sample) and assume I have the two data fields save as JavaScript variables on my website. Can I send the 2 unique fields to "Save to Android Pay" API Servers from my website while (or before) the user clicks the "Save to Android Pay" button?
Got an answer from 'Save to Android Pay' team:
There is a section in the Loyalty.java class that creates an object with specified parameters. The Java quickstart has hard-coded values as an example, but can be easily changed to the variables you use to keep track of user's ID numbers, etc.
You can can insert your user's unique values in this section:
// Define Wallet Instance
LoyaltyObject object = new LoyaltyObject()
.setClassId(issuerId + "." + classId).setId(issuerId + "." + (Math.random()*1000))
.setState("active").setVersion(1L).setBarcode(barcode).setInfoModuleData(infoModuleData)
.setAccountName("Jane Doe").setTextModulesData(textModulesData)
.setMessages(messages).setLinksModuleData(linksModuleData)
.setAccountId("1234567890").setLoyaltyPoints(points);
Also note that in the WobGenerateJwtServlet.java class, it creates a JWT depending on the object type. Specifically for loyalty objects here:
// Create the appropriate Object/Classes
if (type.equals("loyalty")) {
LoyaltyObject obj = Loyalty.generateLoyaltyObject(credentials.getIssuerId(),
context.getInitParameter("LoyaltyClassId"), context.getInitParameter("LoyaltyObjectId"));
obj.setFactory(new GsonFactory());
payload.addObject(obj);

Categories

Resources