I purchased an Apple Magic Keyboard 2 (the US layout model). I own a Macbook Pro 15" (Late 2012), updated to El Capitan (if relevant, this computer was running the El Capitan Beta prior to its release).
I turned on my keyboard for the first time and connected it using the lighting cable. A notification showed up telling me that the Magic Keyboard is ready to use.
When pressing the function keys, they don't perform the function they're labelled for (for example it's impossible to change the volume or brightness). All of the information I found on the internet so far didn't seem to reflect in my current situation.
These keys work correctly with the Macbook's built-in keyboard.
I am using the default US keyboard layout from OS X. When opening the keyboard viewer, the keyboard seems to be recognised as a non-Apple keyboard.
Another situation I've encountered is that when unplugging the keyboard after the initial set up, I get a window called "Keyboard Setup Assistant" which makes me press specific keys on the keyboard in order to recognise it, and ends up determining it is an ANSI keyboard. This seems like a strange behaviour.
EDIT: I also tried toggling the setting to use the F keys as standard function keys on and off, but to no avail.
EDIT 2: before using this new keybaord, I was using the old Apple Magic Keyboard, with the Italian layout, but OS X was configured to use a tweaked US layout (modified using Ukelele). For a while they were both connected to the system. I then unpaired the old keyboard.