The PewDiePie story originated from Parker having similar experiences to Kyle that he had with his step-son. Another influence of the story was the fact that Parker and Stone felt that more people experienced South Park: The Stick of Truth, their video game, through PewDiePie than by actually buying and playing the game themselves. They thought it would be fun to "rip" on this.
The scene in which Randy/Lorde is at the concert and gets into a fight with Iggy Azalea was originally going to be used as the final scene for "The Cissy", the third episode of this season. This idea was scrapped with the intention to use it later; it was used in this episode, but with a few modifications. Sia was originally present but was at some point removed and Randy was going to get in a fight with everyone else, not just one person.
Trey Parker and Matt Stone said on the DVD audio commentary that this episode was originally two separate episodes, one about PewDiePie and one about Lorde. This plan did not materialize because they couldn't figure out an ending that would be long enough to fill up the time for either show. To rectify this, they intended to put them together to make one episode. However, this didn't work either because Parker had written a lot of good material and now felt it needed to be a three-part story arc episode. They considered actually doing this but expected problems with Comedy Central. After shifting back and forth between one episode and three episodes, they finally settled on two partway through the production cycle. In hindsight, they thought it would have been better off if they made it a three-part story.
Pewdiepie makes a cameo in this episode