/** * Ensure global window.optimizely queue has been initialized. */ window.optimizely = window.optimizely || []; function send_optimizely_event(aAct) { if (typeof window.optimizely != "undefined"){ window['optimizely'].push(["trackEvent", aAct]); } } /** * Utility function to clean facet labels * this includes removing the count and normalizing * the ampersand */ clean_facet_name = function(facet){ var facet_out = '' if (!jQuery(facet).hasClass("facetapi-active")) { var facet_html = jQuery(facet).html(); var facet_parts = facet_html.split(' ('); var facet_clean_name = facet_parts[0].replace(/&/g, 'and'); var facet_out = facet_clean_name; } else if (jQuery(facet).hasClass("facetapi-active")) { var facet_html = jQuery(facet).parent().html(); var facet_parts = facet_html.split('a>'); var facet_clean_name = facet_parts[1].replace(/&/g, 'and'); var facet_out = facet_clean_name; } return facet_out; } jQuery(document).ready(function($){ /** * Looks for cb query parameter in the URI * if this variable is present, we know for sure that someone has * sucessfully commented on the site. When this happens, send * google analytics the naked URL for event tracking. */ var cb = extractParamFromUri(document.location.search, 'cb'); if (typeof cb != "undefined"){ gaTrackEvent('comment', 'post comment', window.location.href.split('?')[0]); add_to_email_segment(); } // Track featured work clicks and their relative position $(".view-display-id-feature_work_combined > div").click(function(event) { var clicked_nth = $(this).index() + 1; gaTrackEvent('contextual content click', 'related work ' + clicked_nth, window.location.pathname); }); $(".field_blog_author a").click(function() { gaTrackEvent('contextual content click', 'author byline', window.location.pathname); }); $(".view-id-blog_blocks.view-display-id-block_3 a").click(function() { gaTrackEvent('contextual content click', 'author more', window.location.pathname); }); $(".group_learn_more a").click(function() { gaTrackEvent('contextual content click', 'learn more', window.location.pathname); }); // contact this person email click $('body.node-type-profile div.view-contact-this-person div.views-field-field-web-users-email a').click(function() { gaTrackEvent('contextual content click', 'contact email', window.location.pathname); }); $("nav.navigation a, #navburger-subnav a").not(".has-children").click(function() { var linkto = $(this).html().replace(/&/g, 'and'); gaTrackEvent('main nav', linkto, window.location.pathname); }); $(".prj-feature-share a[href*=facebook]").click(function() { gaTrackEvent('in page', 'like', window.location.pathname); send_optimizely_event('facebook-click'); }); $(".prj-feature-share a[href*=twitter]").click(function() { gaTrackEvent('in page', 'tweet', window.location.pathname); send_optimizely_event('twitter-click'); }); // global search facet events $('body.page-search section.block-facetapi li.leaf a').click(function() { var facet = clean_facet_name(this); if(facet){ gaTrackEvent('facets', 'global', facet); } }); // grant search facet events $('body.page-grants-search-results section.block-facetapi li.leaf a').click(function() { var facet = clean_facet_name(this); if(facet){ gaTrackEvent('facets', 'grants', facet); } }); // termsearch facet events $('body.page-termsearch section.block-facetapi li.leaf a').click(function() { var facet = clean_facet_name(this); if(facet){ gaTrackEvent('facets', 'termsearch', facet); } }); // header social clicks $("#boxes-box-header_social a[href*=facebook]").click(function(e) { e.preventDefault(); gaTrackEvent('Global social', 'Facebook', document.URL); var timeout_func = "window.location.href='" + $(this).attr('href') + "'"; setTimeout(timeout_func, 100); }); // header social clicks $("#boxes-box-header_social a[href*=google]").click(function(e) { e.preventDefault(); gaTrackEvent('Global social', 'Google', document.URL); var timeout_func = "window.location.href='" + $(this).attr('href') + "'"; setTimeout(timeout_func, 100); }); // header social clicks $("#boxes-box-header_social a[href*=twitter]").click(function(e) { e.preventDefault(); gaTrackEvent('Global social', 'Twitter', document.URL); var timeout_func = "window.location.href='" + $(this).attr('href') + "'"; setTimeout(timeout_func, 100); }); // in page social clicks $("button.social-facebook, a.facebook_mobile_header, a.campaign_facebook").click(function() { gaTrackEvent('facebook', 'click-share', document.URL); gaTrackSocial('facebook', 'click-share', document.URL); add_to_email_segment(); send_optimizely_event('facebook-click'); }); // in page google clicks $("button.social-google").click(function() { gaTrackEvent('google', 'click-plus', document.URL); gaTrackSocial('google', 'click-plus', document.URL); add_to_email_segment(); send_optimizely_event('google-plus-click'); }); // in page twitter clicks $("button.social-twitter, a.twitter_mobile_header, a.campaign_twitter").click(function() { gaTrackEvent('twitter', 'click-tweet', document.URL); gaTrackSocial('twitter', 'click-tweet', document.URL); add_to_email_segment(); send_optimizely_event('twitter-click'); }); // in page linkedin clicks $("button.social-linkedin").click(function() { gaTrackEvent('linkedin', 'click-linkedin', document.URL); gaTrackSocial('linkedin', 'click-linkedin', document.URL); add_to_email_segment(); send_optimizely_event('linkedin-click'); }); // in page republish clicks $("button.social-republish").click(function() { gaTrackEvent('republish', 'click-republish', document.URL); add_to_email_segment(); }); // in page email clicks $("button.social-email").click(function() { var ab_click = 'click_' + abt; gaTrackEvent('email to friend', ab_click, document.URL); add_to_email_segment(); }); // timeline clicks $("#timeline li li").click(function() { var timeline_title = $('h4', this).text(); gaTrackEvent('timeline', 'click-dot', timeline_title); }); // timeline nav left $("#timeline-wrapper #timeline-left").click(function() { gaTrackEvent('timeline', 'click-nav', 'left'); }); // timeline nav right $("#timeline-wrapper #timeline-left").click(function() { gaTrackEvent('timeline', 'click-nav', 'right'); }); // Carousel click first item $(".section-front-featured-pager .pager-item:nth-child(1)").click(function() { var slide_title = $(".pager-item-title", this).text(); gaTrackEvent('carousel', 'click-1', slide_title); }); // Carousel click second item $(".section-front-featured-pager .pager-item:nth-child(2)").click(function() { var slide_title = $(".pager-item-title", this).text(); gaTrackEvent('carousel', 'click-2', slide_title); }); // Carousel click third item $(".section-front-featured-pager .pager-item:nth-child(3)").click(function() { var slide_title = $(".pager-item-title", this).text(); gaTrackEvent('carousel', 'click-3', slide_title); }); // Newsletter signup tracking if($("body.page-email-updates").length){ var email_get = extractParamFromUri(document.URL,'email'); var email_referrer = document.referrer; if(email_get && email_referrer){ gaTrackEvent('email_updates', 'signup', email_referrer); } } // track slideshow actions $("button.button-slideshow").click(function() { gaTrackEvent('slideshow', 'click-open', document.URL); }); $("button.button-slideshow-next").click(function() { gaTrackEvent('slideshow', 'click-next', document.URL); }); $("button.button-slideshow-prev").click(function() { gaTrackEvent('slideshow', 'click-previous', document.URL); }); // Attach events once the social header is displayed $('#social-mobile-header').on('mobileSocialHeader', function() { //mobile header facebook clicks $("a.facebook_mobile_header").click(function() { gaTrackEvent('facebook', 'click-share-mobile-header', document.URL); }); //mobile header twitter clicks $("a.twitter_mobile_header").click(function() { gaTrackEvent('twitter', 'click-tweet-mobile-header', document.URL); }); }); // add to superuser segment if they have a repeat campaign cookie if(readCookie('email_campaign_repeat')){ add_to_email_segment(); } });