Younger audiences flocked to “Sausage Party” this weekend, pushing the raunchy, low-budget comedy about a group of grocery products trying to avoid being eaten to an impressive $33.6 million debut.

In order to get members of the so-called Millennial generation to show up in force, Sony Pictures deployed the largest digital marketing campaign in the studio’s history, leaning on social media platforms such as Snapchat, YouTube and Twitter to drive buzz. Typically the studio spends 12% of its marketing budget for a film on digital promotions, but in the case of “Sausage Party,” Sony allocated nearly half of its promotional spending to online efforts.

“We doubled down on digital,” said Rory Bruer, Sony’s distribution chief. “That’s what propelled us into the zeitgeist.”

The bet worked and the core audience was persuaded to turn off or, at the very least, silence their smartphones for the duration of “Sausage Party’s” 88 minute run. Sixty percent of the audience for the film was male and 54% of ticket-buyers were under the age of 25, just the types of consumers Sony was shooting to attract.

It’s easy, however, to see how “Sausage Party” could have failed to resonate with these consumers. Particularly if Sony had opted to go a more traditional route, hawking its wares with a combination of television ads and billboards. Millennials, meaning moviegoers between the ages of 18 and 39, are a notoriously difficult group to attract to theaters. Though they remain the highest percentage of moviegoers, the number of consumers hitting movie theaters in that age group has declined steadily over the past five years, according to the Motion Picture Association of America.

At the same time, it’s a generation that is cutting the cable cord in greater numbers, while turning to streaming services such as Netflix and Hulu for their entertainment. Among customers between the ages of 18 to 29, streaming subscriptions outweigh cable ones. Moreover, one-fourth of those consumers have never had a pay-TV service, according to a recent survey from Clearleap, a video technology firm.  That makes it difficult for studios like Sony to grab customers’ attention during a traditional commercial break. Much of “Sausage Party’s” core audience isn’t watching programming when it originally airs or on ad-supported platforms.

“You have to go where the audience is,” said Paul Dergarabedian, senior media analyst at ComScore. “Younger audiences today are more tech savvy.”

Sony was more than happy to make the digital migration. In order to bolster interest in the film, Sony deployed Seth Rogen to YouTube, where the “Sausage Party” star joined Hannah Hart for an episode of her online series, “My Drunk Kitchen.” It also partnered with BuzzFeed Food on a series of prank videos that had the comic voicing animatronic grocery items that surprise unsuspecting shoppers as they peruse store aisles and fruit displays. The digital shorts were made to be embedded and shared across the likes of Facebook. The studio then teamed with Snapchat to celebrate National Hot Dog Day by allowing fans to create sausage avatars that were again voiced by Rogen. Making ads and spots that were share-able, click-able, tweet-able, and like-able were the guiding principles for Sony as it tried to cut through the clutter.

Digital platforms were important in another way. “Sausage Party” overflows with envelope-pushing jokes, sexual innuendo, and four-letter words, precisely the elements that can’t be promoted on television without getting a hefty FCC fine. But red-band trailers, like the ones that Sony created for “Sausage Party,” can get a lot of attention across social media without running afoul of censors. That made online venues doubly important.  To date the movie’s red band content has been viewed over 224 million times, and “Sausage Party’s” first red band trailer has been seen more than 182 million times. That makes it the most popular red band trailer in the studio’s history.

It wasn’t all online marketing, of course. Sony offered up a long-form spot on AMC’s “Preacher,” the comic book show that Rogen co-produces, as well as advertised during the NBA Finals, and on younger-skewing networks such as Comedy Central and MTV.

All along, the studio positioned “Sausage Party” as the comedy of choice for the SnapChat set. They first screened the film at this spring’s SXSW, an Austin, Texas-based festival where representatives from Hollywood and Silicon Valley cross-pollinate. It then screened the film at this summer’s Comic-Con, allowing them to build enthusiasm among the fanboy crowds. To capitalize on the word-of-mouth, Sony launched the second red band trailer for the film in conjunction with its Comic-Con debut.

At a time when bigger budgeted offerings such as “Suicide Squad” are trying to entice younger moviegoers, the studio recognized that its only advantage was creating viral word-of-mouth. With that in mind, it knew it had to be nimble, digital, and opportunistic.

“You have to reach the movers and shakers of the Twitter-verse for something like this,” said Jeff Bock, an analyst with Exhibitor Relations. “It’s a crazy idea for a comedy and it paid off.”