It starts with a trigger, a prod that propels users into a four-step loop. Think of the e-mail notification you get when a friend tags you in a photo on Facebook. The trigger prompts you to take an action—say, to log in to Facebook. That leads to a reward: viewing the photo and reading the comments left by others. In the fourth step, you inject a personal stake by making an investment: say, leaving your own comment in the thread. This pattern kicks off a cycle that lodges behaviors in the basal ganglia. That’s the part of the brain where automatic behaviors are stored and where, according to neuroscientists, they last a lifetime, notes Nir Eyal, an entrepreneur turned user-experience guru who has become Silicon Valley’s most visible advocate of habit-forming technology.