My captured referals differ hugely from Google Analytics - php

I use Google Analytics on my site and now I need to track refer-urls from some customers, i.e. I need to see the exact url they come from. My clients use a special url when referring to my site so I set up a capture of HTTP_REFER in the script on that landing page. The url the customers use is unique so there's no chance that a user accidently types that url.
The problem I face is that when i record HTTP_REFER to my database I get a lot of calls without refer, but with correct GUID and other parameters. That means that I know that they came from e.x. www.client1.com but I need to know the exact refer e.g. www.client1.com/objectx.
When I compare my database with Google Analytics the difference is huge as well. Last month Analytics said that about 1100 clicks came from my clients but my recorded clicks from my landing page are 5400. I can't see what should be wrong with my capture. It works quite simple.
the client has a link to my page with a unique GUID e.g
www.mypage.com/api/123d-213-12321-23434
When the request hits
my site I check the GUID to see if it's a valid customer and then
saves the click in my db along with HTTP_REFER.
I then redirect them to my start page.
Does anyone have any idea why they differ so much and witch one is correct?

Related

Is there a way to tell if a user clicked on my google ad?

Google allows you to specify the order id when log a conversion. However, it doesn't link that order to the actual conversion data. It only uses it to avoid duplicates. So in other words, I can't match conversions to orders. I can only see that there has been X USD worth of connversions.
Instead of trying to set up Google Analytics to somehow measure this, it would be a lot easier if I could simply check if the user has in fact clicked on my advert when they submit the order. Then I can track conversions myself and no need to rely on Google. Which gives me a lot more control too.
So when a user places an order, and the conversion logic is kicked off, is there a way to decipher google's cookies so as to know the user clicked on my advert? For example, I clicked on my own advert and now it would be great if I could get the cookie like so:
if (!empty($_COOKIE['ga-advert-triggered']))
{
// do stuff
}
But I dont think Google would make it that easy? Or do they?
Alternatively, is there perhaps a way I can ask Google if the current user has triggered my advert? Maybe their api has a javascript function. Something like:
if (GA.hasTriggeredAdverts()) {
// do stuff
}
Any ideas on how to do this?
Thanks!
You have basically two options.
Add a query parameter to the URL in the ad's link. If the ad leads now to http://example.com/myproduct.php change it to (e.g.) http://example.com/myproduct.php?from=googlead. In the PHP code you check if $_GET['from'] == "googlead" and set a cookie or session variable.
Make the ad point to a redirect page. For example, the ad sends the user to http://example.com/from_google_ad.php which sets the cookie or session variable and then redirects to http://example.com/myproduct.php. Note that the redirect page must be on the same domain or Google will reject the ad.

Why does google UTM code disappear after initial landing page?

Im running a self-hosted wordpress site and I am trying to tailor what secondary content a user sees based off of parameters in the utm code. All I was doing was <?php if (isset($_GET['utm_source'])) {dynamic_sidebar( 'sidebar-1' );}else {dynamic_sidebar( 'sidebar-2' );} ?>
For either testing for a UTM pram or a string variable to display one widget vs the other. After I did this and was testing I realized that the UTM code disappears after a user clicks to the next page or to any other page. i.e the utm query disappears from the end of the URL in the bar (but google is still tracking the session of course, just no visible utm). So after the initial landing page the condition is no longer true
I was wondering if anyone knows why it does this? Because I have been on sites where the UTM stays appended to the URL and when it disappears, like it does for me. Im assuming the tag is saved by wordpress in the database table, but can't find an answer. I am trying to figure out what is going on. and if I should solve my problem by declaring a new variable to check or if I should tell wordpress to continue appending the UTM using a rewrite rule.
It is normal that UTM parameters (like any other parameters) are only used on the landing page.
Google Analytics requires them only on the landing page; these are session based values, so it is enough to see them on the first page call. Google Analytics will automatically attribute all subsequent pageviews in that session to the same visitor (identified by the client id which is stored in a cookie). You can see how this works exactly in the documentation. When the campaign parameter changes Google will start a new session.
Since attribution happens on the Google servers the GA code will do nothing to persist the utm parameters on the client side. It is quite normal that parameters from a link are not passed around though the site - if you want that you have to do some programming and add them yourself. Actually it would be better to set a cookie with the utm values, that way they would not be visible in the URL (which looks odd).
But it is normal that they show only in the incoming link. If you want the parameters to stay appended you have to append them yourself.

Proper Way of Recording Page Views

What is the proper way, using PHP, to record web page views? I believe that currently we just record a view each time a page is hit on, but I am assuming that is including hits from bots, or other things we don't want to be recording.
How can we just record real legit views into our DB and not include stuff that shouldn't be counted as an actual page view?
Thanks!
Use google analytics
To set up the web tracking code:
Find the tracking code snippet for your property.
Sign in to your Google Analytics account, and select the Admin tab. ...
Find your tracking code snippet. ...
Copy the snippet. ...
Paste your snippet (unaltered, in its entirety) into every web page you want to track. ...
Check your setup.
1) Ignore any known bots that visits your web page. (best use robots.txt)
2) Use Ajax call at the end of page to get rid of bouncers (visitors that opens web by mistake and closes it before everything is loaded).
3) I assume you can call Ajax in some delay, so robots will already has left your page and visitor is still browsing it.
4) Record IP addresses and (if possible) some device identifier to find unique visitors.

Need help redirecting and firing a pixel

I'm an affiliate marketer with essentially no programming experience, but I need a little help and I'm hoping you guys can help me out.
Currently I use a simple PHP redirect so that my advertiser can't see the ref URL of the site I have my ads on. (I assume this accomplishes that?)
<?php
header("Location: DESINATION URL");
exit;
?>
The ad server that I use allows me to target or exclude my ad campaigns to/from any user that has fired a particular pixel (iframe or script). The idea is that with this re-targeting capability, you can target your ad campaigns to people who visited a particular website in the past that you have a pixel on.
So, what I need to do is not only redirect users, but I want to figure out how to simultaneously fire either the iframe or script pixel. Here's the idea. Someone that clicks on one of my ads but doesn't end up making a purchase isn't someone that I want to serve ads to over and over again. Once they click, I want them to no longer be eligible to see one of my ads. The only way to do this is to fire a pixel for that user when they click, so that I can then use this retargeting feature of the ad server I use to exclude those users from my campaigns. Make sense?
User lands on the page
pixel fires
page redirects to destination URL
Is this possible?
No, a header-based redirect will ALWAYS show the url to the client. It's essentially telling the browser "hey, go over here and fetch this address". Your server isn't fetching the contents of that address, it's just telling the browser where to go to fetch it itself.
What you want is a proxy - your server fetches the URL and sends the results back to the client.
And what do you mean, "fired a pixel"? Loading a web bug?

How to track relevant views using php

I would like to track all views to a page using php and mysql. I will be tracking the number of times a person viewed the page and the ip address along with the current date. However is there a way to make sure your tracking actual users rather than bots/spiders?
Two options that I see:
Create a "hidden" link on your home page to a honey pot. Any one who hits the honey pot page should be considered a bot and not included in your stats
2: Not a fool proof way, but you could compare the browser's User Agent string to a white list of known web browsers. This string can be spoofed so its not the most reliable.
Personally, I'd go with the first option.
For the honey pot:
on your home page I'd add something like this:
ReallyNotATrap
and on the honey pot page itself something like this:
$BotIp=$_SERVER['REMOTE_ADDR'];
//DB connection
Insert into BlackList($BotIp,$Date,$otherDataYouCareAboutLogging);
//close DB Connection
Then for your stats code simply compare every user's Ip to the BlackList table. If the user isn't on it, record the stats.
EDIT
As pointed out below, googlebot can get tricked by this. If this is something that matters to you (if your just filtering for your own stats and not filtering content it shouldn't matter), include your honeypot page in your Robots.txt. Google will read the text file and avoid the trap. Other nasty bots will fall into it. Since google will avoid our trap, I would also use option 2 and filter out Google's User Agent String from the stats.
The amount of real users should be basically the same number as the number of real users - bots. If you want to you can check the User Agent which will tell you who is browsing the site.
You could try out my tracking script, it's pretty simple to implement and bots and spiders will come up as a bunk browser so it's easy to weed them out. I use this on all my company's sites for analytics. There's one caveat though, if you use this for keyword tracking you may be disappointed real soon because Google is starting to change the structure of their query strings for logged in users.
https://github.com/k4t434sis/tracking.php

Categories