– For the past few years, New Jersey casinos have been losing money like most of their customers — consistently. But in the past six months, the popularity of casino-sponsored online betting has reversed the fortunes of Atlantic City’s gambling palaces, cheering both casino owners and state revenue officials.

New Jersey is one of only three states — Nevada and Delaware are the others — where in-state bettors can log on to websites run by casinos and gamble from the comfort of their couches, rather than going into a glitzy and noisy casino.

Gambling experts say casinos that sponsor their own online wagering are making a smart play for millennials, many of whom prefer online gambling. At least eight states (California, Hawaii, Illinois, Michigan, New Hampshire, New York, Pennsylvania and West Virginia) are considering legalizing casino-run online wagering this year.

State-sanctioned, casino-sponsored online gambling is different from online gambling that originates offshore, which states cannot tax. It is also distinct from state-regulated “daily fantasy sports” sites like DraftKings and FanDuel, which generate taxes and fees for some states.

Chris Grove, a gambling industry consultant who runs the website PlayNJ.com, said online gambling is a key to the growth of casino revenue. “We’ve seen nearly every other form of commerce migrate to the internet — how we shop, how we bank, how we listen to music,” he said. “It doesn’t make sense that gambling would be an exception to that rule and the early results in New Jersey really drive that point home.”

According to the New Jersey Division of Gaming Enforcement, total casino gambling revenue was $763.5 million through April of this year, an increase of 1.7 percent compared to the same period last year. The casinos’ winnings from online gambling, however, were $80.1 million, up 29.5 percent from same period last year.

New Jersey legalized casino-sponsored online gambling in late 2013, but it took casinos some time to create the software to take advantage of the new law, as well as for gamblers to adapt. At first, some casinos only offered a game or two online. According to New Jersey officials, online gambling increased in late 2016 and early 2017, as evidenced by a spike in revenue. The state collected $3.1 million in taxes on online gambling in April, up 23 percent from $2.5 million in April 2016.

From 2007 to 2015, New Jersey casino revenue declined by an average of 7.6 percent annually. This year, thanks in part to the increasing popularity of online gambling, casino revenue is on track for a year-to-year increase for the first time since 2006.

In Nevada and Delaware the impact has been smaller. In Delaware, only three casinos sponsor online gambling, and it has generated revenue of about $200,000 a month. Total casino revenue in Delaware is about $50 million per month.

In Nevada, only two casinos offer internet poker, the only online casino game the state allows. Mike Lawton, senior research analyst at the Nevada Gaming Control Board, said online poker revenue is wrapped into the control board’s report on poker overall, so it’s difficult to determine whether online poker has been a huge hit. But online sports betting, also offered by casinos, “has really taken off,” increasing 5 percent in the first quarter of 2017 compared to the same period last year.

“A lot of the reason for the sports book business taking off is people being able to do it on their phone. It’s a huge convenience,” he said, noting, “We do everything else on our phones.”

Every state that has legal gambling collects taxes or fees from it. There can be a tax on casinos’ revenue, hefty fees to procure a casino operating license, a tax on gamblers’ winnings, an “entertainment tax” on casinos or players, a tax on lottery locations, a tax on poker machines at bars or some combination of the levies. In general, casinos must pay gambling taxes in addition to corporate taxes.

Despite the online gambling spike in New Jersey and elsewhere, overall gambling tax revenue in the states is flat on average, according to Lucy Dadayan, senior research scientist at the Rockefeller Institute of Government.

In 17 states she studied, tax revenue from gambling declined by 0.4 percent in the fourth quarter of 2016, compared to the same quarter of 2015. However, there was some growth in tax revenue in the first quarter of 2017. A big part of the increase was the opening of a new casino in Maryland, she said.

“The overall total tax revenues for casinos should be interpreted with caution and should not be viewed as a positive sign,” she said. She noted that online gambling is not easy to implement and “comes with a lot of regulation.”

Because New Jersey requires people who play online casino games to be in the state, it has developed tracking software to determine a bettor’s location. That means a gambler who lives in Pennsylvania must travel to New Jersey to play an online casino game.

“New Jersey online [gambling] has definitely come on very strong,” said David Schwartz, director of the Center for Gaming Research at UNLV. “People enjoy playing online rather than in casinos.”