Using mixpanel with angular.js - javascript

How can I use mixpanel in SPA? I want to track some events created by user.
When user opens page first time randomly generated ID is given to him. After signing in this action is executed.
mixpanel.alias(data.id);
mixpanel.track('Sign In', {
'Email': response.data.email
});
user.setCurrent(data);
In user.setCurrent function I do this:
mixpanel.identify(data.id);
But in my mixpanel account random ID still given to user? What should I do to prevent this?

Using mixpanel.identify doesn't actually change the ID Mixpanel uses:
On the signup confirmation page, you call mixpanel.alias("john#hotmail.com"). This doesn't actually change his ID - he is still being identified using the random ID we originally assigned him.
What you can do is to add the ID you use in your database to the Mixpanel Person, just like you do with the email at the moment. Then configure the Mixpanel UI to show that column in your reports.
mixpanel.track('Sign In', {
'Email': response.data.email,
'UserId': response.data.id
});

Related

firebase - check if an user is already registered in database

I have a firebase app that is running on mobile devices and now I need to create the web version of it.
At the moment I have integrated firebase ui to give to users the ability to login. Since I need to show a wizard if the user isn't already registered, how I can check if user exists in the database so I can decide if show the wizard or not and then add it to the database?
It sounds like you're looking for the fetchSignInMethodsForEmail method, which returns the list of providers with which a specified email address has previously been signed in to Firebase.
The typical flow is:
Get the email address of the user
Call fetchSignInMethodsForEmail to get a list of providers
If the list is empty, go to your account creation flow
If the list has a single value, show the sign in screen for that provider
If the list has multiple values, show a screen where the user can pick from those providers
I consider you are using firebase auth and firestore, but this is the logic
firebase.auth().onAuthStateChanged(async (user)=> {
if (user == null){
//the user is not signed in, navigate to login screen
}else{
//the user is signed in, try to check if he exists in the database or register him
//let say you are using firestore roo
let user_ = await firebase.app().auth().currentUser
firebase.firestore().collection("collections_of_users").doc(user_.uid).get().then(snap =>{
if(snap.exists){
//the user exists
}else{
//register him, and before make sure his email is verified by checking if emailVerified === true
firebase.firestore().collection("collections_of_users").doc(user_.uid).set({user_mail: user_.email, user_name: "xxx"})
}
})
}
});

Best approach/design to web application?

I have been taking a Node.js course on Udemy and would like to apply some of the knowledge I have gained to create a simple web application. I would like to have a user register, which leads him to an admin panel, this part I already have.
This user (requester) can then refer users (invitees) to this website using a unique link. For example he would click a button to generate a unique hyperlink (my idea for this link was to be the http://websiteurl/userid of the requester who is sending the link).
The requester can then send this link through email to their friends to invite them to the website, once they click the link they are taken to a sign up form and when they fill in the form they are linked (added to an array under the original user).
How would I go about setting up this "session", as in make sure that the form that the invitees fill out is linked to the original requester? How can those forms be generated dynamically on the requester's hyperlink?
I'm not looking for the exact code to do this, but rather validation if my idea for the url is a good approach or if there are other approaches I should consider.
Thanks in advance!
Well, this would require you changing the schema for your database. A user will need to have a property like:
{
referred: []
}
The referred array should contain ids or some sort of reference to a user's referred users.
On the "/:userid" route, the form should submit to the route where a new user is created and have a parameter with the user ID. In this case, I am using query parameters.
So if a person were to visit /foo, they would get a form that would post to a URL like /new?userid=foo.
In that route, you can do something like this (assuming Express):
app.post("/new", (req, res) => {
const userID = req.query.userid;
const newUser = // create user normally
if(userID) {
// `userID` referred this user
const referrer = getUser(userID);
referrer.referred.push(newUser);
save(referrer);
}
});
The getUser function should returning the current user, and you should modify the referred property with the new user. This code was merely an outline and you should update the user in your database.
In a nutshell, a form should post to /new?userid=foo, and when creating a new user, if this parameter is present, you can update the database entry for the user id in the parameter with the id of the new user.

Where to put User ID in a GA tracking flow?

I am using React-GA, and it works as expected, but I have a requirement to put user email in event tracking:
I see this in the example:
ReactGA.event({
category: 'Editing',
action: 'Deleted Component',
label: 'Game Widget'
});
I have a email of each user as a string. Where do I better put it in the request?
yes i am with #davids answer but i want to give more proper answer.
first you need to import react-ga module
import ReactGA from 'react-ga';
and than whenever you initialize google analytics you can set userId there
ReactGA.initialize('UA-000000-01', {
gaOptions: {
userId: xxx-xxx-xxx-xxx
}
});
Or if you want to set userId after user logs into your system, than you can do the following way
1. initialize google analytics without userId
ReactGA.initialize('UA-000000-01');
2. and just after login you can set userId
ReactGA.set({ userId: 123 });
ref: https://github.com/react-ga/react-ga#reactgasetfieldsobject
You should not use an email address as that is personally identifiable information and as such to track it in GA is against Google's terms and conditions.
User ID ("userId") should be setup in the "initialize" or "set" GA command, not in an event. User ID is scoped to the user, so it shouldn't ever change for a user. Also, you'll have convert email to an anonymous (non-PII) id before it's used as userId
ReactGA.initialize('UA-000000-01', {
debug: true,
titleCase: false,
gaOptions: {
userId: 123
}
});
User ID doc: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#userId

Meteor Accounts add extra fields

How do I add extra fields to the Meteor Accounts?
Ex: Profile Picture, Header Picture field etc...
I know how to change the password Accounts.setUsername(userId, username);
But how would I add an extra field to the Accounts?
You need to update the users collection in mongo. The way to access it is by using
Meteor.users.update(Meteor.userId(), {
$set:{
profile: {
picture: 'url-to-picture'
}
}});
According to documentation, anything that need to be updated by user should be stored under the profile key
profile: an Object which the user can create and update with any data.
Do not store anything on profile that you wouldn't want the user to
edit unless you have a deny rule on the Meteor.users collection.

Facebook api, get user liked page using FB.api

Using this method, facebook will return an object of the user's liked pages
FB.api('/me', {fields: 'gender, first_name, last_name, email, likes'}, function(response) {
console.log(response);
}
result
email: "ariel#dropbox.com"
first_name: "Ariel"
gender: "female"
id: "178006027123671"
last_name: "Yeung"
likes: Object data: Array[2]
However, I only want to get the object whether this user is liking my facebook page
As https://developers.facebook.com/docs/graph-api/reference/user/likes describes, you can ask whether the user likes a certain page using
/me/likes/{page_id}
Since you are asking for specific user fields already, you probably don’t want to make a separate API call for that – but you can fit it in there as well, using field expansion:
/me?fields=gender,first_name,last_name,email,likes.target_id({page_id})
If the user likes that particular page, you get a likes property in the response data.
(Not sure if that works using the syntax you are using currently as well, passing the fields via object, but you can simply try: {fields: 'gender, …, likes.target_id({page_id})'} … let us know if that works, thanks.)
Edit: Although this will still work, as long as you get user_likes permission from the user, Facebook will not approve the use of that permission for this singular purpose. Like Gating in any way, shape or form is not allowed any more.
You canot get the list of users liking you page via graph api. So, you can not check wether or not a user has like your page directly.
You already have the likes of a user, just loop through them and check that your page is liked or not.

Categories