0 ){ $arr=normalize_array_val($options['excludecategories']); if( !empty($arr) && is_array($arr) && in_array($x, $arr) ) $allow = FALSE; unset($arr); } break; case 'tag': $x = 0; if( is_numeric($_REQUEST['v']) ) $x = intval($_REQUEST['v']); if( $x>0 ){ $arr=normalize_array_val($options['excludetags']); if( !empty($arr) && is_array($arr) && in_array($x, $arr) ) $allow = FALSE; unset($arr); } break; case 'page': $x = 0; if( is_numeric($_REQUEST['v']) ) $x = intval($_REQUEST['v']); if( $x>0 ){ $arr=normalize_array_val($options['excludepages']); if( !empty($arr) && is_array($arr) && in_array($x, $arr) ) $allow = FALSE; unset($arr); } break; case 'post': $x = 0; if( is_numeric($_REQUEST['v']) ) $x = intval($_REQUEST['v']); if( $x>0 ){ $arr=normalize_array_val($options['excludeposts']); if( !empty($arr) && is_array($arr) && in_array($x, $arr) ) $allow = FALSE; unset($arr); } break; default: $arr=normalize_uri(normalize_array_val($options['excludeuri'], "\n")); if( !empty($arr) && is_array($arr) && in_array($_REQUEST['v'], $arr) ) $allow = FALSE; unset($arr); break; } } } $custom_header = array( 'Content-type'=>'application/x-javascript; charset=UTF-8', 'Cache-Control'=>'no-cache, must-revalidate', 'Expires'=>'Mon, 26 Jul 1997 05:00:00 GMT', 'Connection'=>'close', ); foreach($custom_header as $k=>$v){ header($k.': '.$v); } die("AGA_CUSTOM_FILTER=".($allow ? "true":"false").";"); } // Determine the location function gapp_plugin_path() { return plugins_url('', __FILE__).'/'; } /* Utilities */ function print_gzipped_page($custom_header=array()) { $encoding = false; if( !headers_sent() && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ){ if( strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false ){ $encoding = 'x-gzip'; }elseif( strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false ){ $encoding = 'gzip'; } } if( $encoding ){ $contents = ob_get_contents(); ob_end_clean(); if( !empty($custom_header) ){ foreach($custom_header as $k=>$v){ header($k.': '.$v); } } header('Content-Encoding: '.$encoding); print("\x1f\x8b\x08\x00\x00\x00\x00\x00"); $size = strlen($contents); $contents = gzcompress($contents, 9); $contents = substr($contents, 0, $size); print($contents); exit(); }else{ if( !empty($custom_header) ){ foreach($custom_header as $k=>$v){ header($k.': '.$v); } } ob_end_flush(); exit(); } } function normalize_array_val($str='', $sep=','){ $result = array(); if( empty($str) ) return FALSE; $dummy = explode($sep, $str); foreach($dummy as $i){ $i = trim($i); if( !empty($i) && is_numeric($i) && intval($i)>0 ){ $i = intval($i); if( !in_array($i, $result) ) $result[] = $i; }elseif( !empty($i) && !in_array($i, $result) ){ $result[] = $i; } } unset($dummy); if( empty($result) ){ return FALSE; }else{ return $result; } } function get_array_checkbox_el($name, $opt=array(), $selected=array()){ $result = ''; if( empty($name) || empty($opt) || !is_array($opt) ) return $result; $count = 0; foreach($opt as $k=>$item){ $count++; } $count_per = round($count/3); $i = 0; $ended = false; foreach($opt as $k=>$item){ if( $i == 0 ){ $result .= '
'; $ended = false; } $i++; $is_selected = ''; if( !empty($selected) && is_array($selected) && in_array($k, $selected) ) $is_selected = 'checked="checked" '; $result .= ' '.$item.'
'; if( $i>= $count_per ){ $i = 0; $result .= '
'; $ended = true; } } $result = trim($result); if( !empty($result) ){ if( !$ended ) $result .= ''; $result .= '
'; } return $result; } function array_checkbox_val($el=array(), $sep=','){ $result = array(); if( empty($el) || !is_array($el) ) return ''; foreach($el as $i){ $i = trim($i); if( !empty($i) && is_numeric($i) && intval($i)>0 ){ $i = intval($i); if( !in_array($i, $result) ) $result[] = $i; }elseif( !empty($i) && !in_array($i, $result) ){ $result[] = $i; } } if( empty($result) ){ return ''; }else{ return implode($sep, $result); } } function get_my_current_ip(){ $ipaddress = ''; if (getenv(HTTP_X_FORWARDED_FOR)) { $ipaddress = getenv(HTTP_X_FORWARDED_FOR); } else { $ipaddress = getenv(REMOTE_ADDR); } return $ipaddress; } function normalize_single_uri($str=''){ $result = ''; $str = strtolower(trim($str)); if( empty($str) ) return $result; $dummy = explode('?', $str); $str = trim($dummy[0]); $dummy = explode('#', $str); $str = trim($dummy[0]); unset($dummy); $result = $str; if( stripos($result, get_bloginfo('home')) === 0 ){ $result = str_ireplace(get_bloginfo('home'), '', $result); } return trim($result); } function normalize_uri($arr=array()){ $result = array(); if( empty($arr) || !is_array($arr) ) return FALSE; foreach($arr as $s){ $s = normalize_single_uri($s); if( !empty($s) && !in_array($s, $result) ) $result[] = $s; } if( empty($result) ){ return FALSE; }else{ return $result; } } function wildcard_uri($arr=array()){ $result = array(); if( empty($arr) || !is_array($arr) ) return FALSE; $wildcard = FALSE; foreach($arr as $s){ $dummy = explode('.', $s); if( stripos($s,'*')!==FALSE && count($dummy) == 4 ){ $wildcard = TRUE; $new_ip = ''; $done = FALSE; for($k=0;$khook) { wp_enqueue_script('jquery'); ?> optionname); return ''; } function textinput($id) { $options = get_option($this->optionname); return ''; } function config_page() { $options = get_option('AsyncGoogleAnalyticsPP'); if ( (isset($_POST['reset']) && $_POST['reset'] == "true") || !is_array($options) ) { $this->set_defaults(); echo "

Async Google Analytics settings reset to default.

\n"; } if ( isset($_POST['submit']) ) { if (!current_user_can('manage_options')) die(__('You cannot edit the Async Google Analytics for WordPress options.')); check_admin_referer('analyticspp-config'); foreach (array('uastring', 'dlextensions', 'dlprefix', 'artprefix', 'comprefix', 'comautprefix', 'blogrollprefix', 'domainorurl','position','domain', 'excludeposts', 'excludeuri', 'excludeips') as $option_name) { if (isset($_POST[$option_name])) $options[$option_name] = $_POST[$option_name]; else $options[$option_name] = ''; } foreach (array('extrase', 'imagese', 'trackoutbound', 'trackloggedin', 'admintracking', 'trackadsense', 'userv2', 'allowanchor', 'rsslinktagging', 'advancedsettings', 'trackregistration', 'useasync','customfilter') as $option_name) { if ( isset($_POST[$option_name]) ){ $options[$option_name] = true; }else{ if( $option_name == 'useasync' ){ $options[$option_name] = true; }else{ $options[$option_name] = false; } } } foreach (array('excludecategories', 'excludetags', 'excludepages') as $option_name) { if (isset($_POST[$option_name])){ $options[$option_name] = array_checkbox_val($_POST[$option_name]); }else{ $options[$option_name] = ''; } } update_option('AsyncGoogleAnalyticsPP', $options); echo "

Async Google Analytics settings updated.

\n"; echo ""; } if( !isset($options['useasync']) ){ $options['useasync'] = true; } ?>

Async Google Analytics for WordPress Configuration

'uastring', 'label' => 'Analytics Account ID', 'desc' => 'What\'s this?', 'content' => '
' ); $rows[] = array( 'id' => 'useasync', 'label' => 'Use asynchronous tracking method instead of traditional.', 'desc' => 'All google analytics will use Asynchronous Tracking method.', 'content' => $this->checkbox('useasync'), ); $rows[] = array( 'id' => 'position', 'label' => 'Where should the tracking script be placed?', 'content' => '' ); $rows[] = array( 'id' => 'trackoutbound', 'label' => 'Track outbound clicks & downloads', 'desc' => '', 'content' => $this->checkbox('trackoutbound'), ); $rows[] = array( 'id' => 'advancedsettings', 'label' => 'Show advanced settings', 'desc' => 'Only adviced for advanced users who know their way around Google Analytics', 'content' => $this->checkbox('advancedsettings'), ); $rows[] = array( 'id' => 'customfilter', 'label' => 'Enable/Disable custom filter tracking', 'desc' => 'Enable/Disable tracking for specified categories, tags, posts, pages, URL, or Visitor with specified IP.', 'content' => $this->checkbox('customfilter'), ); $this->postbox('gasettings','Async Google Analytics Settings',$this->form_table($rows)); $rows = array(); $rows[] = array( 'id' => 'admintracking', 'label' => 'Track the administrator too', 'desc' => 'Not recommended, as this would schew your statistics.', 'content' => $this->checkbox('admintracking'), ); $rows[] = array( 'id' => 'trackloggedin', 'label' => 'Segment logged in users', 'content' => $this->checkbox('trackloggedin'), ); $rows[] = array( 'id' => 'dlextensions', 'label' => 'Extensions of files to track as downloads', 'content' => $this->textinput('dlextensions'), ); $rows[] = array( 'id' => 'dlprefix', 'label' => 'Prefix for tracked downloads', 'content' => $this->textinput('dlprefix'), ); $rows[] = array( 'id' => 'artprefix', 'label' => 'Prefix for outbound clicks from articles', 'content' => $this->textinput('artprefix'), ); $rows[] = array( 'id' => 'comprefix', 'label' => 'Prefix for outbound clicks from links in comments', 'content' => $this->textinput('comprefix'), ); $rows[] = array( 'id' => 'comautprefix', 'label' => 'Prefix for outbound clicks from comment author links', 'content' => $this->textinput('comautprefix'), ); $rows[] = array( 'id' => 'blogrollprefix', 'label' => 'Prefix for outbound clicks from blogroll links', 'content' => $this->textinput('blogrollprefix'), ); $rows[] = array( 'id' => 'domainorurl', 'label' => 'Track full URL of outbound clicks or just the domain', 'content' => '', ); $rows[] = array( 'id' => 'domain', 'label' => 'Domain Tracking', 'desc' => 'This allows you to set the domain that\'s set by setDomainName for tracking subdomains, if empty this will not be set.', 'content' => $this->textinput('domain'), ); $rows[] = array( 'id' => 'trackadsense', 'label' => 'Track AdSense', 'desc' => 'This requires integration of your Analytics and AdSense account, for help, look here.', 'content' => $this->checkbox('trackadsense'), ); $rows[] = array( 'id' => 'extrase', 'label' => 'Track extra Search Engines', 'content' => $this->checkbox('extrase'), ); $rows[] = array( 'id' => 'imagese', 'label' => 'Track Google Image Search as a Search Engine', 'desc' => 'This functionality is in beta, and not confirmed to work yet', 'content' => $this->checkbox('imagese'), ); $rows[] = array( 'id' => 'userv2', 'label' => 'I use Urchin', 'content' => $this->checkbox('userv2'), ); $rows[] = array( 'id' => 'rsslinktagging', 'label' => 'Tag links in RSS feed with campaign variables', 'content' => $this->checkbox('rsslinktagging'), ); $rows[] = array( 'id' => 'trackregistration', 'label' => 'Add tracking to the login and registration forms', 'content' => $this->checkbox('trackregistration'), ); $rows[] = array( 'id' => 'allowanchor', 'label' => 'Use # instead of ? for Campaign tracking?', 'desc' => 'This adds a setAllowAnchor call to your tracking script, and makes RSS link tagging use a # as well.', 'content' => $this->checkbox('allowanchor'), ); $this->postbox('advancedgasettings','Advanced Settings',$this->form_table($rows)); $rows = array(); $opt = array(); foreach(get_categories('hide_empty=0&hierarchical=0') as $cat){ $opt[$cat->term_id] = $cat->cat_name; } $rows[] = array( 'id' => 'excludecategories', 'label' => 'Disable tracking for following categories', 'desc' => 'All checked categories will not be tracking.', 'content' => get_array_checkbox_el('excludecategories', $opt, normalize_array_val($options['excludecategories'])), ); $opt = array(); foreach(get_tags('hide_empty=0&hierarchical=0') as $tag){ $opt[$tag->term_id] = $tag->name; } $rows[] = array( 'id' => 'excludetags', 'label' => 'Disable tracking for following tags', 'desc' => 'All checked tags will not be tracking.', 'content' => get_array_checkbox_el('excludetags', $opt, normalize_array_val($options['excludetags'])), ); $opt = array(); foreach(get_pages('hierarchical=0') as $page){ $opt[$page->ID] = $page->post_title; } $rows[] = array( 'id' => 'excludepages', 'label' => 'Disable tracking for following pages', 'desc' => 'All checked pages will not be tracking.', 'content' => get_array_checkbox_el('excludepages', $opt, normalize_array_val($options['excludepages'])), ); $rows[] = array( 'id' => 'excludeposts', 'label' => 'Disable tracking for following posts', 'desc' => 'Please enter the post ID seperated by commas.', 'content' => $this->textinput('excludeposts'), ); $rows[] = array( 'id' => 'excludeuri', 'label' => 'Disable tracking for following URL/URI', 'desc' => 'Please enter the url/uri. One per line.', 'content' => '', ); $rows[] = array( 'id' => 'excludeips', 'label' => 'Disable tracking for visitor from following IP', 'desc' => 'Please enter the IP. One per line. If you want to exclude yourself from being tracking, then you can add your IP here.', 'content' => 'Your current IP Address is '.get_my_current_ip().'
', ); $this->postbox('customgafilter','Custom Filter Settings',$this->form_table($rows)); $rows = array(); $rows[] = array( 'id' => 'allow_linkback', 'label' => 'May I add credit link?', 'desc' => 'Any credit link would be appreciated. This would help us to tell the world about this great plugin. Only small text at the bottom of your website and I believe it would not bother you. Your website / blog also will be added to our blogroll then we have get connected each other ^_^', 'content' => $this->checkbox('allow_linkback'), ); $this->postbox('gacredits','Little credit link would be appreciate',$this->form_table($rows)); ?>
plugin_like(); $this->plugin_support(); $this->news(); if( stripos(get_bloginfo('home'), 'minilibra.com') !== FALSE ) $this->plugindev_support_news(); ?>



Async Google Analytics is not active. You must enter your UA String for it to work.

"; } // end warning() } // end class AGA_Admin $aga_admin = new AGA_Admin(); } //endif /** * Code that actually inserts stuff into pages. */ if ( ! class_exists( 'AGA_Filter' ) ) { class AGA_Filter { /* * Insert the tracking code into the page */ function spool_analytics() { $options = get_option('AsyncGoogleAnalyticsPP'); if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) { //USE ASYNC METHOD if( $options["useasync"] ){ echo "\n".''; //USE TRADITIONAL METHOD }else{ if ( !is_404() && $options["extrase"] ) { echo ''."\n"; } echo ''."\n"; }////END OF TRADITIONAL METHOD } else if ( $options["uastring"] != "" && current_user_can('edit_users') && !$options["admintracking"] ) { echo ""; } else if ( $options["uastring"] == "" && current_user_can('edit_users') ) { echo ""; } } function spool_analytics_async_head() { $options = get_option('AsyncGoogleAnalyticsPP'); if( $options["useasync"] ){ if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ){ echo "\n".''; } else if ( $options["uastring"] != "" && current_user_can('edit_users') && !$options["admintracking"] ) { echo ""; } else if ( $options["uastring"] == "" && current_user_can('edit_users') ) { echo ""; } } } function spool_analytics_async_foot() { $options = get_option('AsyncGoogleAnalyticsPP'); if( $options["useasync"] ){ if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ){ echo "\n".''; } else if ( $options["uastring"] != "" && current_user_can('edit_users') && !$options["admintracking"] ) { echo ""; } else if ( $options["uastring"] == "" && current_user_can('edit_users') ) { echo ""; } } } /* * Insert the AdSense parameter code into the page. This'll go into the header per Google's instructions. */ function spool_adsense() { $options = get_option('AsyncGoogleAnalyticsPP'); if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) { echo ''."\n"; } } /* Create an array which contians: * "domain" e.g. boakes.org * "host" e.g. store.boakes.org */ function ga_get_domain($uri){ $hostPattern = "/^(http:\/\/)?([^\/]+)/i"; $domainPatternUS = "/[^\.\/]+\.[^\.\/]+$/"; $domainPatternUK = "/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/"; preg_match($hostPattern, $uri, $matches); $host = $matches[2]; if (preg_match("/.*\..*\..*\..*$/",$host)) { preg_match($domainPatternUK, $host, $matches); } else { preg_match($domainPatternUS, $host, $matches); } return array("domain"=>$matches[0],"host"=>$host); } function ga_parse_link($leaf, $matches){ if( isset($_SERVER["HTTP_HOST"]) ){ $origin = AGA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]); }else{ $origin = AGA_Filter::ga_get_domain(get_bloginfo("home")); } $options = get_option('AsyncGoogleAnalyticsPP'); // Break out immediately if the link is not an http or https link. if (strpos($matches[2],"http") !== 0) $target = false; else $target = AGA_Filter::ga_get_domain($matches[3]); $coolBit = ""; $extension = substr($matches[3],-3); $dlextensions = split(",",$options['dlextensions']); $async_used = FALSE; if( $options["useasync"] ) $async_used = TRUE; if ( $target ) { if ( $target["domain"] != $origin["domain"] ){ if ($options['domainorurl'] == "domain") { $coolBit .= ($async_used) ? "javascript:_gaq.push(['_trackPageview','".$leaf."/".$target["host"]."']);" : "javascript:pageTracker._trackPageview('".$leaf."/".$target["host"]."');"; } else if ($options['domainorurl'] == "url") { $coolBit .= ($async_used) ? "javascript:_gaq.push(['_trackPageview','".$leaf."/".$matches[2]."//".$matches[3]."']);" : "javascript:pageTracker._trackPageview('".$leaf."/".$matches[2]."//".$matches[3]."');"; } } else if ( in_array($extension, $dlextensions) && $target["domain"] == $origin["domain"] ) { $file = str_replace($origin["domain"],"",$matches[3]); $file = str_replace('www.',"",$file); $coolBit .= ($async_used) ? "javascript:_gaq.push(['_trackPageview','".$options['dlprefix'].$file."']);" : "javascript:pageTracker._trackPageview('".$options['dlprefix'].$file."');"; } } if ($coolBit != "") { if (preg_match('/onclick=[\'\"](.*?)[\'\"]/i', $matches[4]) > 0) { $matches[4] = preg_replace('/onclick=[\'\"](.*?)[\'\"]/i', 'onclick="' . $coolBit .' $1"', $matches[4]); } else { $matches[4] = 'onclick="' . $coolBit . '"' . $matches[4]; } } return '' . $matches[5] . ''; } function ga_parse_article_link($matches){ $options = get_option('AsyncGoogleAnalyticsPP'); return AGA_Filter::ga_parse_link($options['artprefix'],$matches); } function ga_parse_comment_link($matches){ $options = get_option('AsyncGoogleAnalyticsPP'); return AGA_Filter::ga_parse_link($options['comprefix'],$matches); } function the_content($text) { $options = get_option('AsyncGoogleAnalyticsPP'); if (!is_feed() && isset($options['trackoutbound']) && !empty($options['trackoutbound']) && $options['trackoutbound']) { static $anchorPattern = '/(.*?)<\/a>/i'; $text = preg_replace_callback($anchorPattern,array('AGA_Filter','ga_parse_article_link'),$text); } return $text; } function comment_text($text) { $options = get_option('AsyncGoogleAnalyticsPP'); if (!is_feed() && isset($options['trackoutbound']) && !empty($options['trackoutbound']) && $options['trackoutbound']) { static $anchorPattern = '/(.*?)<\/a>/i'; $text = preg_replace_callback($anchorPattern,array('AGA_Filter','ga_parse_comment_link'),$text); } return $text; } function comment_author_link($text) { $options = get_option('AsyncGoogleAnalyticsPP'); if( isset($options['trackoutbound']) && !empty($options['trackoutbound']) && $options['trackoutbound'] ){} else{ return $text; } if (current_user_can('edit_users') && !$options["admintracking"]) { return $text; } static $anchorPattern = '/(.*\s+.*?href\s*=\s*)["\'](.*?)["\'](.*)/'; preg_match($anchorPattern, $text, $matches); if ($matches[2] == "") return $text; $target = AGA_Filter::ga_get_domain($matches[2]); $coolBit = ""; if( isset($_SERVER["HTTP_HOST"]) ){ $origin = AGA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]); }else{ $origin = AGA_Filter::ga_get_domain(get_bloginfo("home")); } $async_used = FALSE; if( $options["useasync"] ) $async_used = TRUE; if ( $target["domain"] != $origin["domain"] ){ if ($options['domainorurl'] == "domain") { $coolBit .= ($async_used) ? "onclick=\"javascript:_gaq.push(['_trackPageview','".$options['comautprefix']."/".$target["host"]."']);\"" : "onclick=\"javascript:pageTracker._trackPageview('".$options['comautprefix']."/".$target["host"]."');\""; } else if ($options['domainorurl'] == "url") { $coolBit .= ($async_used) ? "onclick=\"javascript:_gaq.push(['_trackPageview','".$options['comautprefix']."/".$matches[2]."']);\"" : "onclick=\"javascript:pageTracker._trackPageview('".$options['comautprefix']."/".$matches[2]."');\""; } } return $matches[1] . "\"" . $matches[2] . "\" " . $coolBit ." ". $matches[3]; } function bookmarks($bookmarks) { $options = get_option('AsyncGoogleAnalyticsPP'); if( isset($options['trackoutbound']) && !empty($options['trackoutbound']) && $options['trackoutbound'] ){} else{ return $bookmarks; } $async_used = FALSE; if( $options["useasync"] ) $async_used = TRUE; if (!is_admin() && (!current_user_can('edit_users') || $options['admintracking'] ) ) { foreach ( (array) $bookmarks as $bookmark ) { $target = AGA_Filter::ga_get_domain($bookmark->link_url); $sitedomain = AGA_Filter::ga_get_domain(get_bloginfo('url')); if ($target['host'] == $sitedomain['host']) continue; if ($options['domainorurl'] == "domain") { if( $async_used ){ $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:_gaq.push(['_trackPageview','".$options['blogrollprefix']."/".$target["host"]."']);"; }else{ $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$target["host"]."');"; } } else if ($options['domainorurl'] == "url") { if( $async_used ){ $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:_gaq.push(['_trackPageview','".$options['blogrollprefix']."/".$bookmark->link_url."']);"; }else{ $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$bookmark->link_url."');"; } } } } return $bookmarks; } function rsslinktagger($guid) { $options = get_option('AsyncGoogleAnalyticsPP'); global $wp, $post; if ( is_feed() ) { if ( $options['allowanchor'] ) { $delimiter = '#'; } else { $delimiter = '?'; if (strpos ( $guid, $delimiter ) > 0) $delimiter = '&'; } return $guid . $delimiter . 'utm_source=rss&utm_medium=rss&utm_campaign='.urlencode($post->post_name); } } } // class AGA_Filter } // endif /** * If setAllowAnchor is set to true, GA ignores all links tagged "normally", so we redirect all "normally" tagged URL's * to one tagged with a hash. Needs some work as it also needs to do that when the first utm_ var is actually not the * first GET variable in the URL. */ function ga_utm_hashtag_redirect() { if (isset($_SERVER['REQUEST_URI'])) { if (strpos($_SERVER['REQUEST_URI'], "utm_") !== false) { if( isset($_SERVER['SERVER_NAME']) ){ $url = aga_current_protocol().$_SERVER['SERVER_NAME']; }else{ $url = get_bloginfo("home"); } if ( strpos($_SERVER['REQUEST_URI'], "?utm_") !== false ) { $url .= str_replace("?utm_","#utm_",$_SERVER['REQUEST_URI']); } else if ( strpos($_SERVER['REQUEST_URI'], "&utm_") !== false ) { $url .= substr_replace($_SERVER['REQUEST_URI'], "#utm_", strpos($_SERVER['REQUEST_URI'], "&utm_"), 5); } wp_redirect($url, 301); exit; } } } function aga_current_protocol($echo=FALSE){ $url = 'http://'; if ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != ""){ $url = 'https://'; } if($echo){ echo $url; }else{ return $url; } } function get_aga_source_async($echo=FALSE){ $url = aga_current_protocol(); if ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != ""){ $url .= 'ssl'; }else{ $url .= 'www'; } $url .= '.google-analytics.com/ga.js'; if($echo){ echo $url; }else{ return $url; } } function im_your_friend(){ echo ''."\n"; echo ''."\n"; } function add_me_on_footer(){ $options = get_option('AsyncGoogleAnalyticsPP'); $more_style = ''; if( $options['allow_linkback'] ){ $more_style = 'margin:0!important;padding:0!important;text-align:center!important;font-size:8px!important;font-weight:normal!important;'; }else{ $more_style = 'display:none;visibility:hidden;'; } echo '

site tracking with Asynchronous Google Analytics by WordPress Expert at Web Design Jakarta.

'."\n"; } $agaf = new AGA_Filter(); $options = get_option('AsyncGoogleAnalyticsPP'); if (!is_array($options)) $aga_admin->set_defaults(); if( !isset($options['allow_linkback']) ){ $options = get_option('AsyncGoogleAnalyticsPP'); $options['allow_linkback'] = true; update_option('AsyncGoogleAnalyticsPP',$options); } if ( $options['allowanchor'] ) { add_action('init','ga_utm_hashtag_redirect',1); } if (isset($options['trackoutbound']) && !empty($options['trackoutbound']) && $options['trackoutbound']) { // filters alter the existing content add_filter('the_content', array('AGA_Filter','the_content'), 99); add_filter('the_excerpt', array('AGA_Filter','the_content'), 99); add_filter('comment_text', array('AGA_Filter','comment_text'), 99); add_filter('get_bookmarks', array('AGA_Filter','bookmarks'), 99); add_filter('get_comment_author_link', array('AGA_Filter','comment_author_link'), 99); } if ($options['trackadsense']) add_action('wp_head', array('AGA_Filter','spool_adsense'),10); if ($options['position'] == 'footer' || $options['position'] == ""){ if( $options["useasync"] ){ add_action('wp_footer', array('AGA_Filter','spool_analytics_async_foot'),999); add_action('wp_head', array('AGA_Filter','spool_analytics_async_head'),1); }else{ add_action('wp_footer', array('AGA_Filter','spool_analytics')); } }else{ add_action('wp_head', array('AGA_Filter','spool_analytics'),20); } if ($options['trackregistration']) add_action('login_head', array('AGA_Filter','spool_analytics'),20); if ($options['rsslinktagging']) add_filter ( 'the_permalink_rss', array('AGA_Filter','rsslinktagger'), 99 ); if( function_exists('add_action') ) add_action('wp_head', 'im_your_friend', 1); if( function_exists('add_action') ) add_action('wp_footer', 'add_me_on_footer', 999); ?>