You are asking a question about sex/gender initially, so I'll answer that first.
To begin, what is the point of the data? How will you and your company use this data? For example, will it help identify what types of advertisements to display?
Anyhow, it's always good to start with understanding why you are doing something in the first place. This will help you frame your design intent, and come up with solutions for it.
In survey creation, typically you would ask the question like "Which gender do you identify with" giving the choices "male, female, other." This has been done in numerous academic studies and even seen on websites. It's a safe way to asking the question.
Next, if you are asking about race. Well, it really depends on how specific the data needs to be that you are trying to collect.
For example, you could use a drop-down menu, with something like:
◦ Hispanic or Latino
◦ Black or African American
• Native American or American Indian
◦ Asian / Pacific Islander
However, I'll explain how these (dropdowns) are problematic. The issue is that people may identify with different races. So it's best to use checkmarks giving the option for the person to select multiple races, like:
Please select your race(s)
☑ Hispanic or Latino
☐ Black or African American
☐ Native American or American Indian
☐ Asian / Pacific Islander