Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript - Onclick, open new window in background + Google Analytics Outgoing Link Tracking

Posted on 2012-04-12
1
Medium Priority
?
640 Views
Last Modified: 2012-04-24
Hello everyone,

I currently have a page where users enter data in a field and when they click on 'execute', the system runs an internal script and presents them the results.

When 'execute' is clicked, an advertisement window pops up.

Here is what I am after:

1) The popup window to be in the background so it doesn't pop in front of the current window
2) Add Google Analytics outgoing Link Tracking code so I can track through Google Analytics how many people got the popup advertising window.

For the first requirement, here is the portion of the file which performs the popup function and needs to be modified according to my first request (1):
<?php
  if ($ok) {?>
<script type="text/javascript">
window.onload=function() {
  var w = window.open("http://advertising_website","_blank");
  if (!w) alert('Sorry, you have blocked popups')
}
</script>
<?php } ?>


For the second requirement, here is the GA code that I'd normally place in a hyper link within my php files. This needs to be embedded so onclick (when the person clicks on 'execute', its run:

Analytics Outgoing Link Tracking
<a onclick="javascript:_gaq.push(['_trackEvent','Home','click','http://customer_website.com']);" href="http://customer_website.com" target="_blank"> Vist now!</a>


Please let me know if more information is required.

Thank you.
0
Comment
Question by:kosmas
1 Comment
 
LVL 20

Accepted Solution

by:
Proculopsis earned 1500 total points
ID: 37841281
//try:


var w = window.open("http://time.gov","_blank");
w.blur();
window.focus();
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question