<!-- Notice: Codepen requires YouTube embed/video to be muted if using autoplay which adwire adds automatically for seamless user experience. This won't be required on your website. -->

<article>

	<h1>Lorem Ipsum</h1>

	<p>
		Lorem ipsum dolor sit amet consectetur, adipisicing elit. Dolor illum voluptas inventore assumenda? Dolorem explicabo excepturi aperiam deserunt quas! Earum aspernatur provident quisquam quia ad amet! Nemo magni accusamus temporibus.
	</p>

	<p>
		Quae enim minus dolore fugiat vel, nostrum vero magni distinctio cumque inventore omnis saepe? Ratione deleniti magni possimus error earum neque perferendis, sequi mollitia ducimus quasi eligendi illo impedit asperiores.
	</p>

	<p>
		Accusamus soluta voluptas exercitationem ea vel dolor sed recusandae sapiente iure totam veritatis distinctio, quam aut, repellendus ipsam repellat voluptatem inventore et voluptatibus asperiores minima tenetur, reiciendis perspiciatis. Sed, cumque.
	</p>

	<p>
		Veritatis libero quam dicta doloremque laudantium officiis magnam, fugiat quaerat nam ratione. Delectus voluptatem voluptas fugiat, commodi ad esse iusto aut reiciendis ea obcaecati aspernatur laudantium adipisci earum cum iure!
	</p>

	<p>
		Totam ratione quod voluptatibus aut non perferendis quaerat dignissimos odio accusamus id. Laborum, illo neque molestiae consectetur cumque at vel dignissimos eaque earum temporibus asperiores eius enim commodi repellat voluptates.
	</p>

	<p>
		Adipisci eius impedit architecto laudantium sit, obcaecati expedita exercitationem totam sapiente repellendus voluptates, unde quia accusantium! Autem nisi aspernatur debitis, iste, blanditiis dolore aliquam mollitia molestias pariatur veniam illum delectus!
	</p>

</article>
@charset "utf-8";

.adwire-responsive {
	position: relative;
	padding-bottom: 56.25%;
}

.adwire-responsive .adwire {
	position: absolute;
}

.adwire-responsive .adwire,
.adwire-responsive .adwire .adwire-ad,
.adwire-responsive .adwire .adwire-ad > *,
.adwire-responsive .adwire .adwire-ad iframe,
.adwire-responsive .adwire .adwire-ad video {
	width: 100% !important;
	height: 100% !important;
}
"use strict";

const AD_TAG_URL =
	"https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=";

const NUMBER_OF_VISIBLE_PARAGRAPHS = 1;

const paragraphs = document.querySelectorAll(
	`article > p:nth-of-type(n + ${NUMBER_OF_VISIBLE_PARAGRAPHS + 1})`
);

const target = document.createComment("adwire");
const responsiveDiv = document.createElement("div");
responsiveDiv.classList.add("adwire-responsive");
responsiveDiv.appendChild(target);

const message = document.createTextNode("Article continues after ad...");
const buttonText = document.createTextNode("Play ad now!");
const button = document.createElement("button");
button.type = "button";
button.style.marginLeft = ".5em";
button.appendChild(buttonText);

const _display = (value) =>
	paragraphs.forEach((paragraph) => (paragraph.style.display = value));
const hide = () => _display("none");
const show = () => _display("block");

hide();

paragraphs[0].parentNode.insertBefore(message, paragraphs[0]);
paragraphs[0].parentNode.insertBefore(button, paragraphs[0]);

const plugin = (api) => {
	api.play();
	api.on(Adwire.Event.Type.ENDED, () => {
		responsiveDiv.remove();
		show();
	});
};

const start = () =>
	new Adwire({
		adTagUrl: AD_TAG_URL,
		cookies: true,
		height: 315,
		mode: Adwire.Mode.OUTSTREAM,
		terms: true,
		width: 560
	})
		.use(plugin)
		.run(target);

button.addEventListener(
	"click",
	(event) => {
		event.preventDefault();
		message.remove();
		button.remove();
		paragraphs[0].parentNode.insertBefore(responsiveDiv, paragraphs[0]);
		start();
	},
	{ once: true }
);

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css
  2. https://cdn.adwire.dev/latest/adwire.min.css

External JavaScript

  1. https://imasdk.googleapis.com/js/sdkloader/ima3.js
  2. https://cdn.adwire.dev/latest/adwire.min.js