When google updated Firebase, it automatically took care of our old customised events and parameters. However, we now are trying to add more customised events from the new Event-scoped custom dimensions and metrics reporting.
In the new version, there is no such a thing called "register event", which I think it is totally cool, however, now, without having to register an event, even when our event name showed up in the tracking list, it did not capture any data.
Does anyone has encountered similar issues?
func generateInviteFrendsLink(user_id: String) {
let key = "invite_friend"
var parameters = [String: Any]()
parameters["user_id_invite_friend"] = user_id
Analytics.logEvent(key, parameters: parameters)
AppEvents.logEvent(AppEvents.Name(rawValue: key), parameters: parameters)
Related
I am implementing an A/B test with Google Optimize, using a custom activation event. I render different versions of the same React component based on which ID variant I receive from Optimize.
const getVariant = async () => {
if (window.dataLayer) {
await window.dataLayer.push({ event: 'optimize.activate' });
}
const intervalId = setInterval(() => {
if (window.google_optimize !== undefined) {
const variant = window.google_optimize.get(myExperimentId);
setUseTestVariant(Number(variant));
clearInterval(intervalId);
console.log(variant)
}
}, 100);
};
So far this works for randomly generating a different version of the same component corresponding to a variant in my Optimize experiment. But the main objective of the test is to track conversation rate through purchases on the checkout page, where the component which fires the event is not located. So my question is: if the custom activation event is triggered on one page and a session is started, does Optimize know when the user clicks through to the checkout page, or would that page also require an activation event to be pushed to the datalayer? Is it only possible to track interactions on the page that the event was fired from?
Optimize set the _gaexp cookie in your browser, in this cookie stores the experiment variant. This value is stored in google analytics as session scope, therfore, all custom events and transactions in this session will be attached with this variant. You don't need to activate the experiment in another page to save the transaction with the variant.
On the other hand, I donĀ“t know your experiment, but it is usually not a good idea to set Transactions as primary objective. Transactions, in general, are secundary objetives. As primary objetive it is better to use the click in the component that you has changed, for example... add to cart, but depends of the experiment of course
How can I set up FB Analytics in a way that it calculates the average value of a specific custom event? I'm using it on Android. This is the code of the custom event log:
public void logLevel(int level){
Bundle params = new Bundle();
params.putInt("user_level", level);
mFirebaseAnalytics.logEvent("user_level", params);
}
If the app sends level 10 from one device and level 20 from another one I want firebase to display avg level 15. Is that possible?
I think that way you're logging the event and its parameter is correct. Once your event is visible in the Event page of Firebase console, add the parameter in reporting. Make sure to select the right data type, which is Number for your case.
Keep logging the data and you should be able to see similar to this:
This is the score parameter of post_score event in the Firebase demo project. Check it out.
I'm new here and a beginner architect. I'm helping the company I work to design our new product and since I start it, I read a lot about but is never enough.
I decided to use Mediator Pattern (with Mediatr) to call my application layer.
It's cool and I got how to work with it sometimes, but sometimes I get confused.
For example, when we publish a document on our new product, we uses a RequestHandler to do everything and check all rules it needs, it's fine and works like a charm, but, when I want just a quick data, it looks likes too much for just a simple thing.
As an example, every time the user do any kind of action on my web application, I have to check if he is still logged. We have single login per user, so, if the same user connect anywhere else, the older session expires. We do it by saving on database.
On every action of my app, I go to base and check if the session key is the same, as bellow.
var sessionKey = bibliotecaCookie.Value;
var mediator = controller.GetMediator();
var isUserSessionKeyValidRequest = new IsUserSessionKeyValidRequest()
{
sessionKey = sessionKey
};
var isValidSession = mediator.Send(isUserSessionKeyValidRequest).Result;
if (!isValidSession)
throw new UnauthorizedAccessException();
So, I have a RequestHandler (a Handler and a Request which returns a bool) just to check if the user session is ok.
When the handler catches this request, it goes to database and execute a simple rule which is "Is the passed session the same as the stored session key?".
Is it right? Is it the right approach? Did I understand it right?
Thanks in advance guys
The question itself is simple: For a Firebase app, How do you get data that was previously blocked after you login and it is no longer blocked?
As for the details that lead me to ask this question:
In this particular app, I use a simple layout with 2 main sub trees of the root tree, Users and Data. The Data tree is completely readable, anyone can read it at any time. The Users tree is almost the opposite, with the only exception being if you are logged in, then you can read a specific sub tree that is yours only. This leads to the problem that when you go to the page, this data that may be very important to you is blocked until you log in, and there is no way to retrieve it directly. After you log in, however, you now have permission to get that information, but because it was previously blocked, There seems to be no way to extract it.
I have scoured the docs and found only one trigger that might be useful, onAuth(), but even though I can run stuff after login, I cant actually get any data. The best I have gotten so far was a Firebase Reference to the specific sub tree I need, but I cant find any way to actually use that reference to get the Snapshot because it is after the page load. It seems the only option I have is to refresh the page after login and check for login on page load, but that is an awful lot of overhead. Is there some other way to get the data in a tree that you previously did not have permission for after you log in and do have permission to read it? Might there be some reference in the docs I can't find or don't understand that allows me to demand a new snapshot of a fire base reference that is not through triggers that can only be defined on pageload?
Frank van puffelen is right.
It is as simple as:
// setup and other code
ref = new Firebase(URL); //The firebase reference
myuserid = null; //Storage variable
myname = null; //Storage variable
//Other code
//Start of answer code
ref.onAuth(function(authData) { //ON login status change
if (ref.getAuth()) { //Are they logged in
myuserid = authData.uid; //Stores their UID for use
userbase = 'Users/' + authData.uid; //Get path to user info
ref.child(userbase).on("value", function(snapshot, prevChildKey) {
var newData = snapshot.val(); //get data
console.log(newData); //View data, confirmed it was what I wanted
myname = newData.name; //The important data I needed
})
}
})
It seems that so long as this listener is by the other listeners, it works. It runs every time the Authentication is changed, and if they are logged in, attaching a listener to the path with the information and getting it. I am sure there are better ways and probably some problems with this code, but it works for me.
Here's my scenario. When child is added via a browser event post page load, I want to indicate it in the title. But on page load, child added is called as well.
How can I differentiate the initial child added vs one where a new entry has been actually added.
Thanks, Tim
Firebase very intentionally does not distinguish "initial" data from "new" data. This allows for much simpler development in most cases, because you only have to write one set of logic for your data, rather than handling both the initial data case and the new data case.
I can see how you would want the distinction in this case. I'm not sure exactly what you're doing, but if you're building a chat application, you might want to flash the title based on the timestamp of the most recent message rather than whether or not it's a "new" message. This would allow the title to flash on page load if a message was sent slightly before the page was loaded, which may be desirable. In some other cases, you may actually want to flash the title for unread data, and you may want to consider marking children as "read" and flashing the title only for children that show up without the "read" bit. This would allow things to work seamlessly across page refreshes.
If you absolutely need to know when "new" data shows up, you could try using "once" with a "value" event type to get the data, and then use "on" with a startAt query and a "child_added" event type to display new data after that. It would look something like this:
var data = new Firebase(...);
data.once("value", function(d) {
//TODO: display initial state...
data.startAt(null, <last id in snapshot>).on("child_added", function(newMessSnapshot) {
//TODO: render new child and flash title bar.
}
}
Or if you want to do it the really simple way, you could just set a timer so that the title won't flash for any messages received within the first N seconds of page load.
Hope that helps!
You can set up a call that only receives new events rather than ones already existing using the approach from this SO question.
So basically, call .on('child_added'...) with endAt and limit. You still get one entry (the last one), which you can just ignore:
// connect to firebase
var fb = new Firebase(...);
// retrieve the last record from `ref` (endAt() tells it to start at the end)
var first = true;
fb.child('table_name').endAt().limit(1).on('child_added', function(snapshot) {
if( first ) {
// ignore the first snapshot, which is an existing record
first = false;
return;
}
// all records after the last continue to invoke this function
console.log(snapshot.name(), snapshot.val());
});
I thought I would update Kato's answer as Datasnapshot.name() and limit have now both been depreciated.
I decided to make it a bit more simple as well ;)
// connect to firebase
var fb = new Firebase("https://your-firebase-ref/");
var firstTime = false;
fb.limitToLast(1).on('child_added', function(snapshot) {
if (firstTime) {
console.log(snapshot.key(), snapshot.val());
};
firstTime = true;
});
I hope this helps