Skip to content

Instantly share code, notes, and snippets.

View digdeep's full-sized avatar

Narbeh Yousefian digdeep

View GitHub Profile
@digdeep
digdeep / eventid.js
Created January 28, 2015 06:46
Generate event id per page view
<script>
function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 16; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
};
var wp_event_ID = makeid();
@digdeep
digdeep / mailchimpmc_cid.js
Last active August 29, 2015 14:13
maichimp javascript get user id
<script type="text/javascript">
if(window.location.href.indexOf("&mc_cid")) {
var a_mc_cid = location.search.split('&')[7];
var b_mc_cid = a_mc_cid.split('=')[1];
var a_mc_eid = location.search.split('&')[8];
var b_mc_eid = a_mc_eid.split('=')[1];
dataLayer.push ({ 'event': 'mailchimp', 'eventCategory': b_mc_cid, 'eventAction': b_mc_eid, 'eventLabel': '{{WPeventId}}', 'nonInteraction': 1 });
};
</script>
@digdeep
digdeep / ismtd.js
Last active August 29, 2015 14:05
isMobileTabletDesktop
if (navigator.userAgent.match(/Mobi/)) {
// mobile!
var windowWidth = window.screen.width < window.outerWidth ?
window.screen.width : window.outerWidth;
if(windowWidth < 683){
deviceType = 'mobile';
} else {
deviceType = 'tablet';
}
}
<script>
var clientId = ga.getAll()[0].get('clientId');
dataLayer.push({
'UAID': clientId,
'event': 'UAID'
});
</script>
@digdeep
digdeep / NASummary.R
Created May 26, 2014 13:54
Functions for working with data in R
NAsummary = function (df, include.nan = FALSE)
{
newdf = data.frame(col = 1:ncol(df), Count = nrow(df), nNA = sapply(df,
function(x) length(x[is.na(x)])))
newdf$rNA = newdf$nNA/newdf$Count
newdf$rNA = trunc(newdf$rNA * 10000)/10000
if (include.nan) {
newdf$nNan = sapply(df, function(x) length(x[is.nan(x)]))
newdf$rNan = newdf$nNan/newdf$Count
newdf$rNan = trunc(newdf$rNan * 10000)/10000