How do I make a website not count my own hits? - django

I have a website programmed in Django, and as part of the website, I have a view counter for individual pages. However, since I test-view my own files rather often, I don't want to count views that I give to my own pages.
Right now, all I do is that when a specific page is requested, it simply updates a "views" variable in the model for that page by increasing it by 1. This is okay for my own purposes - I don't mind recording multiple views by the same person - but I simply don't want my own views to count.
What ways are there to do this? Please advise.

You can set a temporary cookie variable in your browser.
For example, in Chrome, you can use the following or the Resources tab on the Web Inspector:
browse to website
In browser URL bar, type: javascript:document.cookie="my_app_who_am_i=itsa_me_mario"
and pull it back using some django:
request.COOKIES.get('my_app_who_am_i')
Or if you had sessions setup already on your web server, you could set the cookie only when your account logs in.
response = render_to_response(template_name, context)
response.set_cookie('my_app_who_am_i', 'itsa_me_mario')
return response

You could use session for it. And when the session is for example, admin(you) then, don't count it.

You can add a cookie like "ignore_view" and if the cookie is present you don't increase the counter.

Related

Will this cookie track what visitors do after they have clicked on a rep url? The pages they go to, until they leave the site?

As I have no idea of code, html or the programs I am using, I would like to know if this cookie will work the way I want it to.
I would like to know what pages the user visits in the session after he/she has arrived to the website via the url containing: repid.
I have a custom html tag that I have set up in Google tag Manager and the code is:
<script>
var cookieName = "RepUrl";
var cookieValue = "true";
setPersistentCookie(cookieName, cookieValue, 365); // set for 1 year
</script>
The Trigger Type is Page View, Some Page Views, Page Url, Contains, repid
I then went to google analytics and created a Custom Dimension called Rep Url the scope was Session.
After this I go back to google tag manager and create a variable called: Cookie-Page..., Variable type: 1st party cookie and linked to the cookieName: RepUrl (as in the above code).
Then I make another tag, this time it is a google analytics tag type, track type: page view. I then enable overriding settings in this tag and enter my google analytics id UA-xxxxxxxxx-x . I go to more settings, custom dimensions and enter the index number of the custom dimension I created in google analytics and in the dimension value, I enter the variable I created in tag manager called: Cookie-Page...
After all this I then went to customization, custom reports in analytics created one for the custom dimension (Rep Url) with added filters: Sessions, Avg. Session duration, Entrances/Pageviews, Pages/Session, Users.
I would like to know from start to end if this cookie will work the way I would like it to. All help would be greatly appreciated!
The GTM/GA setup will work, but you might not get the results that you were hoping for in the custom reports.
One reason is that you're setting the cookie once the user, enters the site and arrives at the page with RepUrl, but by that time, the hit for the page view would already be sent to GA thus not capturing into the custom dimension until subsequent hits. This would throw off the sessions, entrances metric in the custom reports.
You could consider looking into creating a custom segment that isolates sessions with the parameter "repurl". This would work if repurl would always be how the user enters the site/starts the session.
Another solution would be to abandon the javascript for setting the cookie, but instead, user the URL variable in GTM and capture the RepUrl parameter that way and set it on pageview.

Display content on web page depending on Google Analytics data

Is it possible to use data from Google Analytics when someone visits my web page?
I would like to get information about the visitor, eg:
location
how many times he visited the page
from where he comes
time spent on website
etc
And depending on those informations display proper content. Or even add them (silently) to the contact form.
Is it possible to use the data collected by Google Analytics or should I create my own mechanism based on cookies? Maybe any other solution?
This isn't possible. Universal Analytics uses a cookie with an ID for the user and handles the rest on the server, so there's no data available to you. However, all of the info that Google is tracking is accessible to you.
location you can get via the users IP
visits you can get by setting a cookie on each user and tracking sessions
referrer should be in the request headers
time spent can be tracked the same way that ga does, but keeping track of the time everytime the user creates another hit

different values of a django session variable in different tabs

Consider the following scenario:
User searches for something and a list (request.session['List']) is created
User can filter this list via an ajax call
Now the user opens up a new tab, does another search, so now the session variable List is set to the new list for the other search
User goes back to the first tab and filters the results again. This time, the filter results come from the new list in the other tab as the session variable has changed
Is there a way to set different values for a session variable for different tabs? or any other solution for this problem?
There is no easy way to do this and it's not Django specific. Check this question:
How to differ sessions in browser-tabs?.
Session based on cookie will not certainly work as cookie is common between tabs for a specific site. Solutions based on URLs with session or local storage have their own issues and in general this is not a good idea because it adds a complexity that is not required in most cases.
In your case, why don't you store the list as JavaScript data or local storage? In that case each tab has its own data.
The server application identifies your requests and session by your session ID, this means that it does not know about tabs and such. In fact, if you give me your session ID, I will get the same list(see Session Hijacking not to get into such troubles).
That being said, if you really want to do that, you could play around with saving user-agent into your session, or make use of request.is_ajax()
You could have session['List'] = ... and session['List_ajax'] = ...`
Then you whould do:
return session['List_ajax'] if request.is_ajax() else sessoion['List']

Distinguish between facebook app iframe and genuine site visit (django app)

I'm trying to distinguish between a web request coming from inside the iframe of my app in facebook vs a regular web visit. That way I can deliver the correct layout.
I had set a session variable when the first iframe request comes into my server (facebook sends a POST param called signed_request to your default canvas url), but then if the user actually visits me website after (outside of facebook) they get iframe layout delivered instead of what my site should look like.
I've looked through all the META info that come in with the iframe request and I dont see anything that would allow me to distinguish the two.
Any help would be much appreciated.
UPDATE: I'm using AppEngine as my application host
The easiest way is to make a unique url for access from Facebook, e.g. if your website is www.site.com then set up either fb.site.com or www.site.com/fb on your server and point it to the same place as www.site.com (and of course set your Facebook app settings to use the alternate url). Then your server code can easily check the accessing url to determine whether to format for Facebook or standalone website.
Another approach is to combine a session variable on the server-side with some javascript on the client-side. You can set a session variable when you receive the signed_request parameter, and then check it on each page load. As long as the session variable is set, you output iframe format and add a bit of javascript code to each page. The javascript checks to make sure the page is still in an iframe using something like if (window.self!=window.top) { //inside iframe }. If not inside an iframe it means the session variable is now stale, so the js jumps to some url that tells the server to clear it and then re-display the page in regular layout.

In Webtrends, what is the difference between a HIT, a VISIT and a PAGE VIEW

I cannot seem to find any straight and clear documentation explaining the differences between these value types. Hits used to be any call to the server regardless of the file type, but Webtrends only tracks page views, so how is a page view different for a hit? As for visits, I assume that 1 visit can produce multiple page views.
I am seeking enlightenment.
Xv
UPDATE:
This is a screen cap of the results im trying to understand.
Hit - any and every request (image, html, css, js etc...)
PageView - every request to a page (html, aspx, asp, php etc...)
Visit - a session, the duration of someone coming to your website, regardless of the number of page views they have generated
These are fairly generic terms and this usage is accepted in most web tracking lingo.
I don't know about Webtrends, but the lingo normally goes something like this:
Hit: a request to the web server. While this could be a page, it could also be an image, CSS file, etc.
Page view: a request to the web server that is a page.
Visit: a unique page view. (unique as in, from the same IP address or same client). Visits depend on what the time frame for unique is; i.e., visits/month is not the same as adding up all of your visits/day.
Ultimately, Hits in this case are equal to page views.
Hope this helps anyone encountering the same issue with Webtrends.