Skip to content

Instantly share code, notes, and snippets.

@bactisme
Last active December 8, 2016 14:20
Show Gist options
  • Save bactisme/e5aa4e488276ca6ac8c7223b0d235427 to your computer and use it in GitHub Desktop.
Save bactisme/e5aa4e488276ca6ac8c7223b0d235427 to your computer and use it in GitHub Desktop.
Track RSS views via a pixel in the content
<?php
function filter_the_content_rss($content){
if ($_SERVER['REQUEST_URI'] == "/feed"){
$url = get_permalink($post);
$additional_text = '<img width=1 height=1 src="/ga_proxy_track.gif?page='.urlencode($url).'" />';
return $content.$additional_text;
}
return $content
}
add_filter('the_content_feed', 'filter_the_content_rss', 10, 1);
# --- RSS TRACKING
location ~ /ga_proxy_track\.gif {
set $mainDomain 'frandroid.com';
set $cid $cookie__ga_cid;
if ($cid = '') {
#set $cid "$request_id"; # only nginx 1.2.7
set $cid "$pid-$date_local";
}
add_header Set-Cookie "_ga_cid=$cid; path=/; domain=.$mainDomain";
set $uip "$remote_addr"; #x_forwarded_for
rewrite ^ /collect?v=1&dl=$arg_page&dh=$host&tid=UA-5414263-24&cid=$cid&uip=$uip&t=pageview break;
proxy_redirect off;
proxy_pass http://www.google-analytics.com;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment