When the mid-season finale of hip-hop drama “Empire” debuts on Fox December 2nd, viewers may have a hard time figuring out when a segment of the show ends and a commercial for Pepsi begins. That will be by design.

On that night, the writers of “Empire” will cap off a storyline that will have been brewing for three weeks: Jamal Lyon, one of the central characters of the hit show, will nab an all-important commercial endorsement from Pepsi, which  in turn will use one of his songs as part of a new ad campaign. As characters on the show prepare to take a gander at Lyon’s new commercial, the show will break for one: a 60-second spot from Pepsi featuring the character and the song. And once the ad – directed by “Empire” creator and executive producer Lee Daniels (above, right) – is complete, viewers will immediately see the next scene of “Empire” start to unfurl.

The show will prepare viewers for the commercial and the commercial will serve as an extension of the show.

“We need to find different ways to get people to talk about our brands,” said Adam Harter, vice president of cultural connections for Pepsi’s beverage business in North America. “We still believe in the 30-second spot, but you have to do so much more than that.”

The Pepsi ad could be a harbinger of things to come. TV networks and Madison Avenue are working diligently to thwart viewers who have more power than ever to skip or ignore the commercials supporting their favorite shows. Where advertisers would once simply run the same ad on network after network almost ad infinitum, many are now crafting spots designed to run only on specific shows at particular moments. Because the commercials are so tied to the programming that drew viewers in the first place, the hope is they will capture the attention of a rising legion of viewers armed with technology that often lets them dismiss advertising entirely.

“We are looking to partner with clients to innovate how we deliver their messaging,” said Toby Byrne, president of ad sales for Fox Networks Group. “That includes brand integrations, like Pepsi and “Empire,’ as well as developing new formats.”

The 30-second TV commercial won’t disappear overnight or even next year, but TV outlets are placing emphasis on “bespoke” ads that echo the programs which they accompany. At AMC, ads from Microsoft and Hyundai featuring zombies or themes related to zombie attacks have become a frequent sight during showings of “The Walking Dead,” a drama centered on how people survive in a world that has become populated by the shambling undead. NBC has for two years enlisted retailer Walmart to run ads during its live broadcasts of musicals like “The Sound of Music” and “Peter Pan” that use songs from those productions.

Pepsi is taking things a step further by gaining placement in the show and its storyline and then weaving those elements into an ad that will serve as the final beat in an ongoing plot. Many advertisers have secured placement in scenes and dialogue over the years and others have created show-specific commercials. This concept would seem to mix the two.

While streaming video and mobile tablets are changing the way people watch TV, “you are still going to have major breakout hit shows,” said Pepsi’s Harter. “Part of the challenge is defining which ones have the greatest fit for your brand and then developing a really innovative way to weave your brand into the storyline somehow.”

Advertisers have tested these waters for some time. In the Spring of 2009, ABC allowed Viacom’s Paramount Pictures to launch a trailer for its reboot of “Star Trek” out of the “O” in the logo of its popular drama “Lost” during an episode’s title credits. Pepsi has been one of the marketers trying its hand at the technique. In January of that same year, Pepsi paid NBC to have the producers of “Saturday Night Live”craft Pepsi-themed sketches featuring the show’s long-running “MacGruber” character run during commercial breaks of an “SNL” broadcast airing the week of the Super Bowl. “We definitely feel like it’s not a one-off,” a Pepsi spokeswoman told Advertising Age that year. “It’s a very determined step to connect with consumers in a new, contemporary way.”

Both sides stress the marriage of Pepsi and “Empire” is not a shotgun one. The producers had been working on a story arc in which Jamal Lyon seeks a commercial endorsement, said Byrne, and “it felt more organic to the storyline if you had a real brand. Pepsi was a natural fit. “Discussions began in the early part of 2015, he said. Indeed, Pepsi is the exclusive beverage sponsor of “Empire” this season and is part of an effort that has the show run with fewer ads than is the norm for an hour-long drama.

Pepsi, meanwhile, had been working with Wasserman Media Group, a sports and entertainment marketing consultancy led by Casey Wasserman, to find new ways of breaking out in TV shows and movies. Dana Walden, one of the co-chairs and co-CEOs of Fox Television Group, made the “Empire” opportunity known, Harter recounted. Tony Sella, a Fox ad-sales executive, helped cement the plan, which also utilized Pepsi’s media-buying agency, OMD. Pepsi executives were granted access to “Empire” writers, he said, though producers at the show had final word on how the soda giant would appear in the program.

In last night’s episode, viewers saw a few scenes in which Pepsi invites Jamal to compete to be the new face of its next musical campaign. The character combined music offered to him by both his mother and father to nab the gig. In the next episode, slated to be broadcast on November 25, Lee Daniels will play himself, directing the new ad that will feature the young Lyon. Finally, on December 2, Jamal will unveil his new commercial during a fictional “American Sound Awards” nominations announcement, at which point the show will cut to an ad break and show the actual commercial featuring the character.

Such a move can be fraught with risk, especially if viewers feel they are being distracted from the program by allusions to the advertiser hoping to catch their eye and ear. CBS inserted dialogue about Subway sandwiches into a 2012 episode of “Hawaii Five-0” that generated backlash and Ford Motor’s appearance in an episode of “New Girl” that year partially overwhelmed some of the antics of star Zooey Deschanel in one scene. But there’s an argument to be made for taking a swing. Consider the unpaid appearance of a famous 1971 Coca-Cola commercial earlier this year in the series finale of “Mad Men.” The presence of the ad in the series’ final plot point made so much sense that viewers talked about an ad that had long been buried in the archives of popular culture.

“We are not forcing a square peg into a round hole here,” said Byrne. “We were all very conscious of making sure this was true to the show, and did not turn into some kind of overly commercial execution. Part of the reason it really works is that from conception, it was a marriage that started with the show itself.”

Pepsi intends to run the ad during “Empire” throughout the next half of the season, said Harter. And the company may try to take things even further, he suggested. The beverage marketer is considering re-cutting the ad so it focuses on Jussie Smollett, the actor who plays Jamal Lyon, rather than the character, and seeing if other TV outlets will run it. Whether or not other networks feel the commercial is too closely tied to “Empire” remains to be seen.