Skip to content

Instantly share code, notes, and snippets.

View chipoglesby's full-sized avatar
🏠
Working from home

Chip Oglesby chipoglesby

🏠
Working from home
View GitHub Profile
@chipoglesby
chipoglesby / datalayer.js
Last active August 29, 2015 13:57
Google Tag Manager Data Layer
<script>
datalayer = [];
</script>
@chipoglesby
chipoglesby / Wordpress Data Layer Variables
Created March 11, 2014 13:35
Modified Wordpress datalayer variables for pulling: author names, post types, number of comments, categories, tags and dates into custom variables for the classic version of Google Analytics. Original script provided by Julien Coquet at: http://goo.gl/t3bz0M
<script type="text/javascript">
// URL toolbox - helps grabbing elements in the URL
var _d = document;
var _dl = _d.location;
var _dlp = _dl.pathname;
var _dls = _dl.search;
var _dr = _d.referrer;
// Initialize your data layer and start pushing variables from custom WordPress PHP data layer
dataLayer.push({
@chipoglesby
chipoglesby / example.py
Last active August 29, 2015 14:04
Python Examples
def donuts(count):
if count >= 10:
return 'Number of donuts: many'
else:
return 'Number of donuts: %s' % count
def donuts(count):
text1 = 'Number of donuts: '
if count<10:
text = text1 + str(count)
@chipoglesby
chipoglesby / answer_door.py
Last active February 13, 2016 19:10
Answer the door! A quick gist to show how a computer program would walk through the process of answering the door as if it were human.
def answer_door():
print "The doorbell rings and you open the door"
print "Is this someone that you know?"
answer = raw_input("Answer Yes No or Sketchy.").lower()
if answer == "yes":
print "Hey friend! How's it going? It's so great to see you again!"
elif answer == "no":
print "Oh, hello I do not think we've met before. How can I help you?"
else:
print "It's probably a bill collector! Shut the door!"
@chipoglesby
chipoglesby / random
Created September 3, 2014 00:04
Assign a random Custom Dimension Group
function makeid()
{
var text = "";
var possible = "AB";
for( var i=0; i < 1; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function main() {
MccApp.accounts().withCondition("Cost > 1.00").forDateRange("YESTERDAY").withLimit(50).executeInParallel('runOnEachAccount', 'finished');
}
function runOnEachAccount() {
Logger.log('Starting on: '+AdWordsApp.currentAccount().getCustomerId());
var results = getAccountReport();
Logger.log(results);
return JSON.stringify(results);
}
@chipoglesby
chipoglesby / waiting.js
Last active June 3, 2021 22:02
Google App Script - Is range blank? If so, write predefined values
/***What should this script do?
1. Loop through all of the spreadsheets
2. If the row after the row that contains AssociatedCampaignName is blank, Write "Waiting For Spot" in the next row after the cell that contains AssociatedCampaignName, IE: A2
3. Write "#" in B2:H2
**/
function waiting(){
var ss = SpreadsheetApp.getActive();
for(var n in ss.getSheets()){// loop over all tabs in the spreadsheet
@chipoglesby
chipoglesby / filters.py
Last active August 29, 2015 14:19
Traverse through accounts and return filters for each account
import argparse
import sys
from apiclient.errors import HttpError
from apiclient import sample_tools
from oauth2client.client import AccessTokenRefreshError
def main(argv):
analytics, flags = sample_tools.init(
@chipoglesby
chipoglesby / date.js
Last active May 24, 2018 13:36
Custom Date in Javascript - Looks at today's date and pulls a date range from 2 months ago.
//gets Today's date
var currentDate = new Date();
//Pulls the date and month parts of the date out.
var year = currentDate.getFullYear();
var month = getTwoMonthsAgo(currentDate);
//for formatting.
month = padTwo(month);
@chipoglesby
chipoglesby / ad_id.R
Created April 27, 2015 15:48
ad_id in R
ad_id <- data %>% group_by(CustomerID, Campaign, Adgroup, AdID) %>% summarize(
AverageCpc=round(sum(Cost) / sum(Clicks),2),
Clicks=sum(Clicks),
Impressions=sum(Impressions),
CTR=round(sum(Clicks) / sum(Impressions),2),
Cost=round(sum(Cost),2),
Conversions=sum(Conversions),
CPA=round(sum(Cost) / sum(Conversions),2),
ConversionRate=round(sum(Conversions) / sum(Clicks), 2))
ad_id[ad_id==Inf] <- 0