using php jquery to obtain cookies from users? for advertisement system - php

I want to build my own advertisement system (like those banners you seen on websites), how would I do so? How do I capture the cookies that the users have visited?
I know that if I had google adsense or something, it will display advertisements to users that they have previously visited. The way its able to do so is because its able to access cookies from the users? I was wondering how do I use php or jquery or ajax or something to access those cookies like those ads are?
Any thoughts?
Thanks!

The same-origin policy prevents any site from obtaining cookies or any other data set by other sites. There is no way of knowing which other sites a user has visited, let alone read the cookies set by those sites.
Only the "Referer" HTTP header will tell you about other sites the user has visited, and this will only be one site, and only if it linked to you.
Now, what you are thinking of with Adsense is that Adsense is able to know your behaviour on other sites. However, Adsense can only do that for sites which have Adsense code on them, where the Adsense code involves an iframe or image that sets a cookie from Adsense's domain. So it's not technically reading cookies set by other domains and it's not technically able to know a user's behaviour on other sites, it's just reading back cookies set by Adsense itself when the user visited other Adsense-enabled sites.

Related

Tracking visitors coming from Facebook

I have written a PHP based blog for the company i work for. Not using any frameworks. I am having trouble tracking users who come from my facebook page's posts to my blog (not wordpress).
I have created a shortlink url. Let's say it is sample.co and it redirects traffic to sample.com. Everything seems fine until here. The problem starts here.
I am adding all user's ip's, user agents. But if even i get 500 visits, my code adds somethig like 3.000 visits. Facebook stats and Analytics shows similar stats (~500 visits). I see that ip's added to MySQL are all different. It usually happens with Android users. I have read somewhere that Facebook sometimes renders to their users the actual URL when FB shows the post. I mean instead of the widget, Facebook shows the whole page. I am not quite sure about that to be honest.
To solve this problem, I have created and added an jquery script to my page and listened users' scroll event. It worked great. Not seeing too much traffic. But this time the problem is i am counting less users. Even I get 500 users from facebook and Analytics shows similar results, my script adds only 200-300 to MySQL.
Does anyone know a better way to track real traffic? Or do you aware of such problem?
Thanks
It should be filtered on the basis of user agent.
https://developers.facebook.com/docs/sharing/webmasters/crawler
how to detect search engine bots with php?
Identifying users through IP is a good idea, but if your IP keeps changing, it's a good idea to use cookies.
http://php.net/manual/en/function.uniqid.php
If the cookie does not exist, you should see it as a new user.
I have found the answer. The problem is called preview (prefetch). Here is the link:
https://www.facebook.com/business/help/1514372351922333
Simply, facebook preloads everything when FB shows the thumbnail to the visitor to speed up your page's load speed. They send X-Purpose: preview header. So you can simply check if HTTP_X_PURPOSE header's value is preview or not. If so, do not count it as a visitor.!
Here are more detailed descriptions:
http://inchoo.net/dev-talk/mitigating-facebook-x-fb-http-engine-liger/
http://inchoo.net/dev-talk/magento-website-hammering-facebook-liger/

Stop Facebook probing a site for content with PHP

Okay, so when you post a link on Facebook, it does a quick scan of the page to find images and text etc. to create a sort of preview on their site. I'm sure other social networks such as Twitter do much the same, too.
Anyway, I created a sort of "one time message" system, but when you create a message and send the link in a chat on Facebook, it probes the page and renders the message as "seen".
I know that the Facebook probe has a user agent of facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php), so I could just block all requests from anything with that user agent, but I was wondering if there's a more efficient way of achieving this with all sites that "probe" links for content?
No there's no fool-proof way to do this. The easiest way to achieve something like this is to manually block certain visitors from marking the content as seen.
Every entity on the web identifies itself with a user agent, although not every non-human entity identfies itself in an unique way there are online database like this one that can help achieve your goal.
In case of trying to block all bots via robots.txt, not every bot holds up to that standard. I will speculate that Facebook may try to prevent malware from being spread across their network by visiting any shared link.
you could try something like this in your robots.txt file
User-agent: *
Disallow: /

Facebook App won't work if website not defined

I'm using the plugin Like 2 Unlock for jQuery.
I'm creating WP plugin and adding this plugin to lock some settings content.
When liked, it will be unlocked and people able to manage settings.
The facebook App need the website added to the Facebook App for it to work. Since this is going to be WP plugin, it will be hosted on others people domains. Well, in this case it will not work because their domain won't match with my domain in FB app.
Do the facebook app settings have something where you don't need to specify your website and this way no need to be tied to a specific domain?
Like Gating is not allowed and not possible anymore: https://developers.facebook.com/docs/apps/changelog
You must not incentivize people to use social plugins or to like a Page. This includes offering rewards, or gating apps or app content based on whether or not a person has liked a Page. It remains acceptable to incentivize people to login to your app, checkin at a place or enter a promotion on your app's Page. To ensure quality connections and help businesses reach the people who matter to them, we want people to like Pages because they want to connect and hear from the business, not because of artificial incentives. We believe this update will benefit people and advertisers alike.

How to know if user came from a Facebook link?

If there is a link posted on Facebook to my website, and a user follows it, I would like to display custom content using PHP. I tried with the following method...
$_SERVER['HTTP_REFERER']
Facebook must block this feature because it is not working. Is there a method for this that actually works with Facebook?
This news is a year old, yet I see they are still using it.. I post it here because It is still pretty informative The srouce of the link is https://www.facebook.com/note.php?note_id=10151070897728920
Restricting the Referrer
We still need to let the websites you navigate to know the traffic is
from Facebook, but we also want to prevent them from reading the full
source url. Otherwise, they could know where on the site you were when
you clicked their link. In order to strike this balance, we've taken
advantage of a new feature called the meta referrer, currently
available in Chrome 17+ and Safari 6+. This allows us to specify how
much of the source url to share with the external site via the Referer
header. If you're using one of these supported browsers you can take
advantage of this new feature. Otherwise, your browser will be routed
to the slightly slower older system.
This change should reduce the impact of the link shim on your browsing
(especially when accessing Facebook from a cellular network) and
should help save around a second for a typical user.

iframes for ads? getting user information?

I was trying to do something like Google's Adsense. I believe they use javascript? But is using iFrame a good idea to have someone put on their site if they want to display ads? Would iFrames able to capture user's data information such as cookies (how adsense works, they get users cookies--that's why they can display ads of sites you've visited, correct me if I'm wrong)?
If this works, how would I able to get users cookies? Is it possible? How does google get users cookies?
Thanks for your help in advance!
(how adsense works, they get users cookies--that's why they can display ads of sites you've visited, correct me if I'm wrong)?
You are wrong. Google can only access Google's cookies. It's a big point in cookie security; no browser will allow you to get to other sites' cookies. Google can use cookies to identify you, but can't use them to see your behaviour on non-Google sites.
AdSense knows what you've been browsing by checking what links you click on Google Search and other services, what Ads you click on, what pages you visit that have AdSense in them (window.top.document.location) and which pages you visit them from (window.top.document.referrer), and probably more methods that people smarter than me at Google come up with :)
EDIT: as shown in comments, in fact one can't rely on top properties.
No you can't get these cookies. They're stored to be readable only by the domain AdSense uses to log people.
This is why an iframe is used, it allows google to load a specific url on a domain they control, the url contains an identifier telling them what AdSense campaign is being used.
Besides, the cookie which is present (but not accessible by you) doesn't contain any information about the user itself. It is instead just an identifier to link the person to data which is already present on the google servers.

Categories