How to count when a link is clicked? - java

My webpage have number of links referring to other sites. On every click of the link I have to count that this particular link was clicked from my site.
How can I do this? I am using JSP as view technology with tomcat as web Server.

If you are using google analytics it is easy to setup javascript to record the clicks. This would be far easier than setting up your own redirection as you can still use actual url anchors instead of urls that go through your server.

google analytics has something called event tracking
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

Related

how to reload every tab of browser which have open our webpages

gmail use some functionality by which they reload all tabs for the login. that means if we open login form of gmail in different different tabs. then login in single tab gmail automatically reload all the pages and redirect to mail page . how it is possible ?
is there any particular frame work to implement this?
You have multiple possibilities, like:
- Websockets
- Push notifications
- Long polling
I won't recommend you any tools for that, as this may change over time, you will find plenty of resources on Google.
If you are using Chrome browser, then I would suggest you to add an extension like "Reload All Tabs". Once you added this extension you can easily reload all the open tabs by clicking the icon of the extension.

How to automate test google analytics on every event fired using Selenium WebDriver

I am working on Google Analytics automation test with Selenium WebDriver java bindings. Our site has Google Analytics tracking events set on important elements on the site. I need to verify that on clicking a certain element under test, the Google Analytic event is in fact fired.
I'm testing it on FireFox. When I click F12, I can see in the console that a Google Analytics is fired with message GET http://www.google-analytics.com/__utm.gif on each element click event.
SampleCode :-
WebDriver wd = new FirefoxDriver();
wd.get("http://www.dummyExample.com/");
wd.findElement(By.linkText("Document Referece")).click();
wd.findElement(By.id("Ex2vc2")).click();
How can I achieve this task? I have googled it but could not find good answers. If anyone can help me with some references or sample code I would be very Thankful.
Good way to test GA is by using javascript. Example shows tests with phantomjs, because it's faster with js stuff, but i think you could use FF or other browsers as well.
Also Author added github link with code to try it. The main approach of test is cool, but it may take time to create code for that and support it later.
http://viget.com/extend/testing-google-analytics-with-phantomjs
Second way is to use HttpProxy. AFAIK there was tool - BrowserMobProxy. You'll be able to sniff all requests on testing website, but they in HAR format. So the algorithm is simple, enable proxy, open website, do actions, sniff requests, parse them and assert the values.
Change endpoint and save all requests to assert them. So usually analytics sends requests to the same url, like 'http://google.com/analytics' or whatever. So, you can change this behavior on testing webserver. F.e. add this url to /etc/hosts with localhost address. And then all requests on webserver which are sent to GA domain will be received by webserver.
That will require extra programming. But it's the cleanest way for testing IMHO.
It can be done using Java script command to capture the event triggered in browser and same script will capture event for different browser(tested for chrome and Firefox).
Basically it is the same way as we do in console window to capture event
**window.dataLayer[0]**.event
just store this value in some variable and compare with expected event, it will give the first event which got triggered and to move next event just use
((JavascriptExecutor) driver).executeScript("window.dataLayer.shift() ");
which will go and capture next event.
I recommend using Charles Proxy charles to capture and verify analytics calls using it's web interface / API. For example, if you wanted to check that a call to action was firing the correct event you would:
Start recording using the Charles API
Click the button using Selenium
Stop the recording using the Charles API
Retrieve the recorded session as JSON using the Charles API
Check for the session for the expected analytics acceptance criteria
An example video can be found here.
You can't capture the output from the console tab by pressing F12 in terms of automation.
You need to fire the click function through automation script and then you can check the list of events fired in google analytics tool. For that sign up in this URL http://www.google.com/analytics/
Set your URL and domain here. Then after executing your tests on events fired come to the analytics tool and check the output.

Monitor google search in Java

for my master thesis I need to keep track of google searches that the users perform. It should be a web project. At first I want to setup a server (that acts like a proxy) to monitor all actions (search queries) performed by the user.
The server should deliver the google search page. I need to keep track of the input the users make and the corresponding results returned from google as well.
My questen is now.. How should I start?
I am not really sure which webserver to use. Should I use tomcat / jetty / or something else?
What about Java Server Faces or Servlets? I worked with JSF long time ago but I am not sure whether its a good decision to use it.
The server should deliver the google search page. Here is my idea: The user connects to my server. The server "reads" the google page and returns it (the source code) to the user. I think of using a listener on the default search field to monitor the search queries of the users. But how is it possible to monitor the results returned from google? The google site itself uses JavaScript I guess. So when the user makes some input it is directly sent to google and the results are directly shown on the webpage thus my webserver does not see anything from the connection between the client and the google services.
The main idea is to monitor a search query and the corresponding search results.
I just need some help and ideas to get started. This is just a small part of my thesis. I do not want to start from zero during my editing time thus I want to make sure that I make the right choices before I start.
Thank you in advance... best regards.
You could use netty as a proxy and just filter and log all search queries. But then again why even use java? From what you describe you wan't to play man-in-the-middle and manipulate/log http traffic.
A quick google search came up with this for python: https://code.google.com/p/proxpy/
Edit: and similar in java https://github.com/adamfisk/LittleProxy

Insert a string and click a button on an ASP page from an Android App without opening the page on the phone

I want to send a string from an android application and dump it in a textbox and then click a button present in the ASP website without opening that website on the phone (the button and the textbox are both present on the asp web page).
I have control over the website (stuff like __VIEWSTATE and the __EVENTVALIDATION strings for the ASP Page are available). I would want to know if there is a way to do this using the __VIEWSTATE and the __EVENTVALIDATION strings. If there is an alternate way, could you please kindly explain me in a step-wise manner.
I supouse that you would like to start some process on web site after click (for example create/read/ someinformation). But in case you have access to web site source it would be better to create some WCF service or ASHX and use it you can send any data and get result of operation.
It is not possibe to click on button without open site. or see Can I fire button click event without firing pageload event?

How to interact with different android browser (get url)

I'm searching for a way to interact with different android browsers.
My intention is to get the URL of the website that is opened by the browser.
My app should run in background and give an alert when a specific url is opened, for now this is for testing and to learn more about android.
Is there any way to tell the browser to pass the url-string to my app everytime a new url is entered?
I've already got the idea to implement a local proxyserver wich checks all http-requests for a specific url, but is there a better way?
aditionally this should work with every browser not just the standard one but also eg. firefox or dolphin.
I already searched the last few days but couldn't find an answer....
Yes, you can do this! Check out http://seleniumhq.org/ for how to automate a web browser.

Categories