This week, Michael Bay’s latest incarnation of Transformers, Age of Extinction, is on pace to become the top grossing film in China ever. By midweek, the action flick is expected to surpass the $218 million that Avatar, the current all-time favorite, made in China after its 2010 release. Over the past weekend, Age of Extinction—widely panned by reviewers as the worst of the four movies of the Transformers franchise—passed China’s no. 2 film, the unexpectedly popular low-budget comedy Lost in Thailand.

How Bay and Paramount pulled this off is an important lesson for other Hollywood studios. Cinema attendance in the United States is falling—this July 4th holiday in the US was one of the worst weekends in decades for box office sales—but China’s film industry is entering a golden age, especially when it comes to action films. It is currently world’s largest box office territory outside of North America:

Age of Extinction’s formula for success has come down to timing and no small amount of flattery. Unlike US blockbusters like Frozen and Despicable Me 2, which were released in China months after their US debuts and made less than a third of their domestic sales, Age of Extinction hit mainland theaters on the same day as in the US. Crucially, that cut down on time for pirated copies to circulate the country.

A co-production between Paramount and Chinese studios, the film includes Chinese actors and Chinese product placements, from Lenovo computers to Yili milk and some of China’s largest banks. The placements weren’t always subtle: “Why would a middle-aged man in the middle of the desert in Texas take out a China Construction Bank card to withdraw money from the ATM?” one Weibo user asked.

Reuters/Tyrone Siu Optimus Prime visits Hong Kong’s Victoria Harbor.

Beyond that, Age of Extinction portrays the Chinese government exactly as Beijing would like. When the plot turns to Hong Kong, a city that in real life is chafing under China’s control, authorities seek help from Beijing when fighting among the giant robots ravages the city. (“We need to call the central government for help now!” one policeman says.)

It’s not just flattering the Chinese central government that seems to have worked, but contrasting Beijing with morally bankrupt US officials. David Cohen of Variety points out that the film shows “Chinese people turning to the central government in a crisis and the authorities responding with firm benevolence. In contrast, craven American authorities hold a gun to the hero’s daughter’s head to make him reveal information.” Perhaps more to the point, the film features Zou Shiming, China’s first Olympic gold medalist for boxing, beating up a corrupt CIA agent.