Skip to content

Instantly share code, notes, and snippets.

// ==== GPT NEWSLETTER CODE ==== //
<div>
<a href="http://[STATIC_HTML_PAGE_URL].html?iu=[AD_ZONE_GOES_HERE]&sz=728x90&tile=1&c=12345678" target="_blank">
<img alt="" border="0" height="90" width="728" src="http://pubads.g.doubleclick.net/gampad/ad?iu=[AD_ZONE_GOES_HERE]&sz=728x90&tile=1&c=12345678">
</a>
</div>
// ==== STATIC HTML PAGE CODE ==== //
@djrosenbaum
djrosenbaum / GPT_Detect_Network_Request_Error.js
Last active March 23, 2018 17:49
Detect Bad Requests network errors sent to DFP
const open = window.XMLHttpRequest.prototype.open;
function openReplacement(method, url) {
if (url.indexOf('https://securepubads.g.doubleclick.net/gampad/ads?') > -1) {
this.onreadystatechange = function() {
if (this.readyState === 4) {
if (!this.status) {
console.log('BAD REQUEST');
}
if (url.indexOf('&trunc=1') > -1) {
// GPT Bookmarklet
// javascript:function init(){let n,e;function t(){const n=$(this).attr("id");e.text(n)}function i(){const n=$(this).text(),e=(t=n,function(n,e){for(let t=0;t<n.length;t++)if(e(n[t]))return n[t]}(window.googletag.pubads().getSlots(),n=>n.getSlotElementId()===t));var t;if(e){const n=e.getResponseInformation();!function(n){const{slot:e,slotId:t,adUnitPath:i,advertiserId:o,campaignId:l,lineItemId:d,creativeId:a,sizes:r,slotTargetingKeys:g,serviceTargetingKeys:s,networkId:p}=n;$("#gpt_debug_overlay").html(`\n <div id="gpt_debug_underlay"></div>\n <ul>\n <button id="gpt_debug_close_overlay">CLOSE X</button>\n <li><b>Slot ID:</b> ${t}</li>\n <li><b>Ad Unit Path:</b> ${i}</li>\n <li><b>Advertiser ID: </b><a href="https://www.google.com/dfp/${p}#delivery/ListOrders/companyId=${o}" target="_blank">${o}</a></li>\n <li><b>Campaign ID: </b><a href="https://www.google.com/dfp/${p}#delivery/OrderDetail/orderId=${l}" target="_blank">${l}</a></li>\n <li><
@djrosenbaum
djrosenbaum / enforceNodeVersion.js
Last active December 31, 2020 01:42
Enforce .npmrc on npm install
/*
Isn't it nice when devs use the same version of node when building on a project
I was searching for a way to enforce .nvmrc before running npm install
There was an npm package
-node-version, but do we really want another dependency in our projects
Add the following line inside of package.json
"preinstall": "node ./enforceNodeVersion"
@djrosenbaum
djrosenbaum / detectWipedAdSlotsFromGPT.js
Last active January 8, 2021 19:12
Detect react wiped ad slots
/*
sometimes react wipes ad slots from the DOM
this code is one option to detect when ad slots have been wiped by react
*/
const slotsWiped = [];
/**
* Checks for wiped ad slots from react
*
@djrosenbaum
djrosenbaum / number-to-letter-to-number.js
Last active January 27, 2021 02:55
incrementally convert from numbers to letters or from letters to number
/*
These javascript functions allow for converting from numbers to letters or from letters to number
I am using these functions to increment channels in a firebase realtime db using numbers as letters
going beyond 26 letters in the alphabet
For example 0 => A or 26 => AA similar to spreadsheet naming
numberToLetters(123) => "DT"
lettersToNumber('DT') => 123
@djrosenbaum
djrosenbaum / war.js
Created March 10, 2021 05:28
Someone on reddit asked about creating a card game of war with javascript
/*
Original Reddit Thread
https://www.reddit.com/r/learnjavascript/comments/m1fwq5/im_learning_javascript_and_desperately_need_help/
*/
// The child’s game, War, consists of two players each having a deck of cards.
// For each play, each person turns over the top card in his or her deck.
// The higher card wins that round of play and the winner takes both cards.
// The game continues until one person has all the cards and the other has none.
// Create a program that simulates a modified game of War.
@djrosenbaum
djrosenbaum / define-request-display.html
Last active October 25, 2022 12:35
Google Publisher Tag: Define Request Display
<!DOCTYPE html>
<html>
<head>
<title>GPT DEFINE REQUEST DISPLAY</title>
<script async="async" src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
window.googletag = window.googletag || { cmd: [] };
@djrosenbaum
djrosenbaum / vacations-to-go-sailing-day-of-week.js
Created January 2, 2023 13:42
vacations to go - include sailing day of the week
// When viewing cruise listings on vacations to go, the sailing dates only include the month and day.
// This script can get pasted into Chrome's browser console to include the day of the week
// For example, to easily view which cruises leave on a specific day of the week such as Thursday
$$('td.dt').forEach(td => {
var textContent = td.textContent.trim();
if (!/\d/.test(textContent)) {
// return if no numbers in the string, invalid date
return;
}