Filtering an IPV6 address in Google Analytics.
Google Analytics will use your IPv6 address.
You may have a website where you want to exclude your own page views and other events from the Google Analytics counts. You can create a view with an IP filter to filter out your own IP and the IP of others you want to exclude. If you entered an IPv4, you may have found that Google Analytics continues to include your clicks. This happens when your ISP is providing both IPv4 and IPv6 IP addresses. You can find out your IPv4 and IPv6 IP addresses here: https://test-ipv6.com/ and in many other websites.
The Google Analytics filter will ignore the IPv4 address when it also receives an IPv6 address. This is purely from my experience with Google Analytics. So, if you really want to exclude your own use of your website, you need to filter on the IPv6 address. The problem is that this address is not static, but changes apparently randomly and with no notification to you.
Send your self an email when your IPv6 changes
To solve this problem and to keep my filter up to date, I created a small .Net Core 2.0 app that can be scheduled to run each time you logon. The app will retrieve your IPv6 address and compare it with an address stored on a small file. If the address has changed, you can update your Google Analytics filter to continue excluding your own clicks from the view stored on Google Analytics. If you need to exclude the actions of others in your work group, you can also install the app on any machines that they use and have the daily result also emailed to you.
.Net Core 2.0 code
The code below will run an ipconfig command, just as if you were running it in a cmd window on your machine. It will extract the IPv6 address and compare it with an address that you have stored on a one line file with that address and then send you an email indicating if the address is the same or is changed.
using System; using System.Diagnostics; using System.IO; using System.Net.Mail;
static void Main(string args)
// write to a temp file the results of ipconfig |find “IPv6” to get ipv6 data
Process findmyip = new Process();
findmyip.StartInfo.FileName = “cmd”;
// add the path to temporarily store your ipconfig information.
String pathTemp = @”C:\Users\…\tempipinfo.txt”;
findmyip.StartInfo.Arguments = @”/c ipconfig | find “”IPv6″” >”””+ pathTemp + @””””;
using (StreamReader sr = File.OpenText(pathTemp))
string s = “”;
s = sr.ReadLine();
int intFirstColon = s.IndexOf(“:”);
new_ipv6 = s.Substring(intFirstColon + 2).Trim();
// Keep a file with current IPv6 address
// add the path where you keep your comparison file with the current IPv6 address.
String path = @”C:\Users\…\ipinfo.txt”;
using (StreamReader sr = File.OpenText(path))
ipv6 = sr.ReadLine();
//send out the email
SmtpClient client = new SmtpClient(“….”);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(“…”, “…”);
MailMessage mailMessage = new MailMessage();
mailMessage.IsBodyHtml = true;
mailMessage.From = new MailAddress(“…”);
System.Text.StringBuilder msg = new System.Text.StringBuilder();
if (new_ipv6.Trim() != ipv6.Trim())
Console.WriteLine(“Alert: Make changes to Google analytics filters.”);
Console.WriteLine(“A new ipv6 has been created.”);
msg.Append(“<h2>Alert: Make changes to Google analytics filters.</h2>”);
msg.Append(“<p>A new ipv6 has been created: ” + new_ipv6.Trim() +”<p>);
mailMessage.Subject = “Alert. IP addres change detected. Daily check for change to IPv6”;
Console.WriteLine(“Tout va bien!”);
Console.WriteLine(“No Change in ipv6″);
msg.Append(” <h2>Tout va bien!</h2>”);
msg.Append(“<p>No Change in ipv6</p>”);
mailMessage.Subject = “No Change. Daily check for change to IPv6”;
mailMessage.Body = msg.ToString();
} // end main
} // end program
} //end namespace
Create the exe file
You can create the exe file using the command line. Navigate to the folder where the project exists.
dotnet publish -c Release -r win10-x64
If you are executing this on another machine, change the machine flag.
Add to your task scheduler
Add the exe to the built-in windows task scheduler.
Handy in many ways
There are other reasons for developers and others testing to know when their IPv6 changes. For example, if you are developing a Facebook App, you will need to whitelist your development machine and will need to keep the IPv6 up to date in the Facebook security panel.