SlideShare une entreprise Scribd logo
1  sur  10
Immunizing your site against Click Fraud How to monitor and prevent excessive ad clicks -- Srikanth Bangalore. Bangalore.srikanth@gmail.com Drupal ID: bangalos
The Scenario: You have signed up with googleadsense Google asks you to paste the following somewhere in your page: <div id="googlehorizontalad2">  <script type="text/javascript"><!-- google_ad_client = "pub-2457397907088834";   /* Footer Ad */ google_ad_slot = "1589389617"; google_ad_width = 728; google_ad_height = 90;   //-->  </script>  <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> You paste it in the footer (block) of all your Drupal pages. You also sometimes show it on the right.
Paranoid: Refresh page on Browser Back Include the following in page.tpl.php: </head><body> <input type="hidden" id="refreshed" value="no"> <script type="text/javascript"> addLoadEvent(refresheverytime);   function refresheverytime(){ var e=document.getElementById("refreshed");    if(e.value=="no")e.value="yes";    else{e.value="no"; location.replace(location.href);}   } </script>
Strategy for detecting Adclick Identify all IFrames for the Ads and associate with each of them an eventhandler function: OnFocus (implies left click) = AdsenseClickX3X; OnMouseOver= DoMouseOverX3X; OnMouseOut= DoMouseOutX3X; Associate with the window window.onbeforeunload= PageUnloadX3X; Definitions: function DoMouseOverX3X() { InIframeX3X = 1; } function DoMouseOutX3X() { InIframeX3X = 0; } function PageUnloadX3X() { //check for right click.   if (InIframeX3X) { 		AdsenseClickX3X ();  		InIframeX3X = 0;   }}
The Javascript Code: (addLoadEvent is a custom function to append the event to the list of on load functions) addLoadEvent(SriInitialize); var InIframeX3X = 0; var DetectedClickX3X = 0; function SriInitialize () { if (document.getElementsByTagName  ||  document.body.all) { variframelist; 	if (document.getElementsByTagName) iframelist = document.body.getElementsByTagName('IFRAME'); 	else iframelist = document.body.all.tags('IFRAME'); 	for (var c = 0; c < iframelist.length; c++) { 		//if (iframelist[c].src.indexOf('googlesyndication.com') != -1) { 		if (iframelist[c].src.indexOf('googleads.g.doubleclick.net') != -1) { iframelist[c].onfocus = AdsenseClickX3X; iframelist[c].onmouseover = DoMouseOverX3X; iframelist[c].onmouseout = DoMouseOutX3X; 		} else {                 } 	}      }    } window.onbeforeunload = PageUnloadX3X;
What to do on click? Fire a GET event (by trying to load an image) function AdsenseClickX3X() {    if (! DetectedClickX3X) { 		DetectedClickX3X = 1; 		//alert ('AdsenseClick'); trackerimg = new Image(); 		trackerimg.src = ‘adsenselock.php?t=1';        }    }
Track the GET[‘t’] events (ad clicks) and page views. $xsql = "SELECT * FROM $sri_dbtable2 WHERE sessid='" . $sessid . "'"; $result = mysql_query ($xsql); if ($result  &&  mysql_num_rows($result) == 1) {   $sri_dbrecord = mysql_fetch_array ($result);   $pages = $sri_dbrecord ['pages'];   $adclicks = $sri_dbrecord ['adclicks'];   if ($_GET['t']) {     $adclicks ++;   } else {     $pages++;   }   $xsql = "UPDATE $sri_dbtable2 SET pages=$pages, adclicks=$adclicks, utime=$curtime WHERE sessid='$sessid'"; mysql_query ($xsql); } else {   $pages = 1;   $adclicks = 0;   if ($_GET['t'])  $adclicks = 1;   $xsql = "INSERT INTO $sri_dbtable2 VALUES ('$sessid', $userid, $pages, $adclicks, '$affiliate', $curtime, $curtime)"; mysql_query ($xsql); } /////////////FINISHED GLOBAL INCREMENT////////////
$blockads = 0; $blockadsPartially = 0; $refresh = 0; $ipaddr_int = ip2long ($_SERVER['REMOTE_ADDR']); $ipaddr = appendcookie($ipaddr_int); $curtime = time(); $expired = $curtime - $trackhours * 3600; $xsql = "SELECT * FROM $sri_dbtable WHERE ipaddr='$ipaddr'"; $result = mysql_query ($xsql); if ($result  &&  mysql_num_rows($result) == 1) { 	$sri_dbrecord = mysql_fetch_array ($result); 	$utime = $sri_dbrecord ['utime']; 	$pages = $sri_dbrecord ['pages']; 	$adclicks = $sri_dbrecord ['adclicks']; 	if ($utime < $expired) { 		$pages = 0; 		$adclicks = 0; 	} 	if ($_GET['t']) { 		$adclicks ++; 		//if ($adclicks >= $maxadclicks)  $pages = $pageviews; 	} else { 	  if ($pages < $pageviews + 2)  $pages ++;         } 	$xsql = "UPDATE $sri_dbtable SET utime=$curtime, pages=$pages, adclicks=$adclicks WHERE ipaddr='$ipaddr'"; mysql_query ($xsql); 	if ($pages == $pageviews + 1) $refresh = 1; 	if ($pages > $pageviews  ||  $adclicks >= $maxadclicks+1) $blockads = 1; 	if ($pages > $pageviews  ||  $adclicks >= $maxadclicks) $blockadsPartially = 1; } else { 	$pages = 1; 	$adclicks = 0; 	if ($_GET['t'])  $adclicks = 1; 	$xsql = "INSERT INTO $sri_dbtable VALUES ('$ipaddr', $curtime, $pages, $adclicks)"; mysql_query ($xsql); } if ($_GET['t']) exit();
Ad Replacement (sort of outside of drupal) Adsenselock.php if ($blockads) ob_start ("ReplaceAds"); else if ($blockadsPartially) ob_start ("ReplaceAdsPartially"); else if ($maxadclicks < 100) ob_start ("InsertTracking"); Page.tpl.php <?phprequire_once 'adsenselock.php'; ?> </head> … </body> <?phpob_end_flush(); ?>
adsenselock.php itself It is ugly, long and unreadable. Sorry! Opening the raw file …  Making it available online.

Contenu connexe

Dernier

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

En vedette (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Immunizing your site against click fraud

  • 1. Immunizing your site against Click Fraud How to monitor and prevent excessive ad clicks -- Srikanth Bangalore. Bangalore.srikanth@gmail.com Drupal ID: bangalos
  • 2. The Scenario: You have signed up with googleadsense Google asks you to paste the following somewhere in your page: <div id="googlehorizontalad2"> <script type="text/javascript"><!-- google_ad_client = "pub-2457397907088834"; /* Footer Ad */ google_ad_slot = "1589389617"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> You paste it in the footer (block) of all your Drupal pages. You also sometimes show it on the right.
  • 3. Paranoid: Refresh page on Browser Back Include the following in page.tpl.php: </head><body> <input type="hidden" id="refreshed" value="no"> <script type="text/javascript"> addLoadEvent(refresheverytime); function refresheverytime(){ var e=document.getElementById("refreshed"); if(e.value=="no")e.value="yes"; else{e.value="no"; location.replace(location.href);} } </script>
  • 4. Strategy for detecting Adclick Identify all IFrames for the Ads and associate with each of them an eventhandler function: OnFocus (implies left click) = AdsenseClickX3X; OnMouseOver= DoMouseOverX3X; OnMouseOut= DoMouseOutX3X; Associate with the window window.onbeforeunload= PageUnloadX3X; Definitions: function DoMouseOverX3X() { InIframeX3X = 1; } function DoMouseOutX3X() { InIframeX3X = 0; } function PageUnloadX3X() { //check for right click. if (InIframeX3X) { AdsenseClickX3X (); InIframeX3X = 0; }}
  • 5. The Javascript Code: (addLoadEvent is a custom function to append the event to the list of on load functions) addLoadEvent(SriInitialize); var InIframeX3X = 0; var DetectedClickX3X = 0; function SriInitialize () { if (document.getElementsByTagName || document.body.all) { variframelist; if (document.getElementsByTagName) iframelist = document.body.getElementsByTagName('IFRAME'); else iframelist = document.body.all.tags('IFRAME'); for (var c = 0; c < iframelist.length; c++) { //if (iframelist[c].src.indexOf('googlesyndication.com') != -1) { if (iframelist[c].src.indexOf('googleads.g.doubleclick.net') != -1) { iframelist[c].onfocus = AdsenseClickX3X; iframelist[c].onmouseover = DoMouseOverX3X; iframelist[c].onmouseout = DoMouseOutX3X; } else { } } } } window.onbeforeunload = PageUnloadX3X;
  • 6. What to do on click? Fire a GET event (by trying to load an image) function AdsenseClickX3X() { if (! DetectedClickX3X) { DetectedClickX3X = 1; //alert ('AdsenseClick'); trackerimg = new Image(); trackerimg.src = ‘adsenselock.php?t=1'; } }
  • 7. Track the GET[‘t’] events (ad clicks) and page views. $xsql = "SELECT * FROM $sri_dbtable2 WHERE sessid='" . $sessid . "'"; $result = mysql_query ($xsql); if ($result && mysql_num_rows($result) == 1) { $sri_dbrecord = mysql_fetch_array ($result); $pages = $sri_dbrecord ['pages']; $adclicks = $sri_dbrecord ['adclicks']; if ($_GET['t']) { $adclicks ++; } else { $pages++; } $xsql = "UPDATE $sri_dbtable2 SET pages=$pages, adclicks=$adclicks, utime=$curtime WHERE sessid='$sessid'"; mysql_query ($xsql); } else { $pages = 1; $adclicks = 0; if ($_GET['t']) $adclicks = 1; $xsql = "INSERT INTO $sri_dbtable2 VALUES ('$sessid', $userid, $pages, $adclicks, '$affiliate', $curtime, $curtime)"; mysql_query ($xsql); } /////////////FINISHED GLOBAL INCREMENT////////////
  • 8. $blockads = 0; $blockadsPartially = 0; $refresh = 0; $ipaddr_int = ip2long ($_SERVER['REMOTE_ADDR']); $ipaddr = appendcookie($ipaddr_int); $curtime = time(); $expired = $curtime - $trackhours * 3600; $xsql = "SELECT * FROM $sri_dbtable WHERE ipaddr='$ipaddr'"; $result = mysql_query ($xsql); if ($result && mysql_num_rows($result) == 1) { $sri_dbrecord = mysql_fetch_array ($result); $utime = $sri_dbrecord ['utime']; $pages = $sri_dbrecord ['pages']; $adclicks = $sri_dbrecord ['adclicks']; if ($utime < $expired) { $pages = 0; $adclicks = 0; } if ($_GET['t']) { $adclicks ++; //if ($adclicks >= $maxadclicks) $pages = $pageviews; } else { if ($pages < $pageviews + 2) $pages ++; } $xsql = "UPDATE $sri_dbtable SET utime=$curtime, pages=$pages, adclicks=$adclicks WHERE ipaddr='$ipaddr'"; mysql_query ($xsql); if ($pages == $pageviews + 1) $refresh = 1; if ($pages > $pageviews || $adclicks >= $maxadclicks+1) $blockads = 1; if ($pages > $pageviews || $adclicks >= $maxadclicks) $blockadsPartially = 1; } else { $pages = 1; $adclicks = 0; if ($_GET['t']) $adclicks = 1; $xsql = "INSERT INTO $sri_dbtable VALUES ('$ipaddr', $curtime, $pages, $adclicks)"; mysql_query ($xsql); } if ($_GET['t']) exit();
  • 9. Ad Replacement (sort of outside of drupal) Adsenselock.php if ($blockads) ob_start ("ReplaceAds"); else if ($blockadsPartially) ob_start ("ReplaceAdsPartially"); else if ($maxadclicks < 100) ob_start ("InsertTracking"); Page.tpl.php <?phprequire_once 'adsenselock.php'; ?> </head> … </body> <?phpob_end_flush(); ?>
  • 10. adsenselock.php itself It is ugly, long and unreadable. Sorry! Opening the raw file … Making it available online.