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.
Related
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.
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.
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?
I'm trying to create a "Email to friend" page using php. The objective of this page is that users can share the page that they are viewing with their friends.
When a user clicks on the 'share' link, it'll redirect user to a page that asks a user to input their own email address and a recipient email address. The subject will be the previous page title and the email body will be the URL of the previous page plus whatever a user may want to include.
I've got the whole concept here but I'm stuck on the implementation stage. I can't seem to figure the best way to pass the previous page title and the page URL to the share page.
Here's what I have thought of so far.
Using POST and GET method doesn't
seem to fit in because there is no
forms involved when a user clicks on
the share link.
Using session and cookies would be
very tedious as it requires assigning
and modifying the cookie / session
each time a user views a page.
Passing variables in URL would make
simply make the URL long and somewhat
undesirable.
Is there any other way that I could use to pass the page title and page url to the next page? I'm open for other suggestions on how I could implement this idea differently. Thanks in advance.
As far as I can see, passing the URL as a GET parameter is indeed the ideal solution.
http://example.com/share.php?url=http%3a%2f%2fwww.example.com
note that
You need to URL-encode the URL you are passing using urlencode()
the total resulting URL should not be longer than 2-4 kilobytes due to restrictions in some browsers.
I don't understand why POST and GET are not an option. Just because there isn't a form on the page doesn't mean you can't put one there. Can the link be turned into a button? If you don't like the look of a button, use CSS. Putting a form on the page would only take a few lines.
I would go for the session approach, even though you consider it tedious. This is called "flash messages" and it's quite commonspread. Zend Framework has these out of the box, CodeIgniter has a neat contributed library for it... Basically, you just need to write a few helper functions and you're set. To get the barebones functionality, you need:
adding a new message
retrieving a message/all messages
clearing messages (could be called after fetching messages)
The messages stored in the session will persist until you clear them, they are immune to redirecting and once you write your helper functions, it'll be as easy as:
//before redirect:
setFlash('You have successfully logged in!');
//after redirect
echo fetchFlash();
clearFlash(); //if fetchFlash doesn't call it automatically
So I wouldn't call it tedious, really. Rather a butt-saver.
I have an affiliate tracking script that is currently being exploited by an affiliate. In the main, site I track the affiliate clicks using this url www.example.com?member=affiliatecode,
then I capture the query string $_GET['member'];
Problem is, an affiliate is exploiting this simple system and page loads on his site is being recorded as clicks going to mine.
What measures can I add to prevent this without changing the affiliate link to my site? An idea that I had is to check if my page has actually been loaded, but how would I do that in PHP?
Thanks
I don't quite grasp the exact problem (or more to the point, exactly how the affiliate is logging hits), but a solution may be to put a image on your page which should ensure that a browser has loaded it. So at the bottom of you page you should insert
<?
if ( isset($_GET['affiliate']) ){
echo '<img src="affimg.php">';
}
?>
And then in the affimg.php, you would log the affiliate and then output a 1x1 image (remembering to set the headers). The downside is that there is no way to stop an affiliate just simply putting that image in to his page and if the affiliate is using an iframe, the image would still be loaded.
A better way may be to simply do some tracking. Rather than just requiring that one page gets visited, change it so that you require two or more using a database to track the ip addresses.
There may be a better way, but then I don't know the exact details.
First, you can never be sure that a bot/script instead a human "clicks" on an image, this is a fact. Secondly, you can make things a bit difficult. An idea would be:
Deliver a banner including a unique link that is triggered via a Javascript-click-event, like:
<img src="http://www.targetsite.com/image.jpg" />
Save the token in your database before and give it a expiration time of some minutes. Then, only count the click if the token is valid later. So your affiliate has to change the "onClick"-Event or parse the source code to extract the token.
As said, it only makes things more difficult. You could also parse your affiliate's site source to see whether there, your banner is "clicked" automatically (which would be very cheeky).
Another addition would be to read a cookie on the client side and attach it to the generated link to implement a check if the client has already requested your target site.
Since you can't protect yourself completely from fakes, you can build several little tools like these that increase safety.
HTH