Concatenating pathname with a virtual URL for Tracking PageView - javascript

I'm using the Contact Form 7 plugin for Wordpress.
It allows you to put in a single line of javascript in the additional settings to trigger some javascript code when the send button is pressed.
My original code looked like this, which works fine:
on_sent_ok: "_gaq.push(['_trackPageview', '/CallbackFormFilled']);"
The "On_sent_ok:" is a specific parameter for the contact form.
I have a requirement where i need to concatenate the pathname of the URL together with the virtual URL i have created in the code above.
I tested concatenation of strings using 'Alert' to make sure i was doing it correctly, but when using the following code my pageview tracking fails
What is the correct syntax for concatenating the strings correctly here?
on_sent_ok: "_gaq.push(['_trackPageview',window.location.pathname+'CallbackFormFilled']);"

Try:
"_gaq.push(['_trackPageview',"/"+window.location.pathname+'CallbackFormFilled']);"

Related

Dynamic facebook like button on localhost

When I use PHP to parse current URL into data-href attribute , the widget breaks and does not render.
Console says its because of empty string parsed into getElementById on the fb script.
Documentation says if i omit the data-href altogether , it defaults to current URL.
When I do that it still doesn't render , only when i predefine some static URL.
I am putting this widget into a "footer.php" that gets included after content on every page.
Is this not working for me on my dev server , because the URL is actually localhost ?
I have a similar problem (with a FB share button, though).
The only answer I can give is: Facebook does not seem to accept localhost in the data-href attribute. For me it works with anything else - e.g. with 127.0.0.1 :) .
Smells like you need to use a work-around :-/.

How to setup Google Content Experiments with the original Url and without query string parameters

I want to set up a Google Content Experiment to do A/B testing on the homepage by testing the addition of a new button in the header menu. When setting up the experiment, Google forces you to have two unique Urls. Another problem is the experiment code adds a query string parameter to the Url which is far from ideal. I don't want to be redirecting users off to a different page or even the same page with a query string parameter. Here is what it looks like: mysite.com?utm_expid=XXXXXXX-X
I found that you can edit Google's experiment JavaScript to get closer to what I want, but I'm not sure if this will collect data correctly or if editing the code is supported.
//This line returns the variation number (0=Control, 1=Variation 1)
//so I can show or hide the test button bases on this variable:
var combination = utmx('combination');
//Removing this line eliminates the redirect:
utmx('url','A/B');
How can I do a simple A/B test while preserving the original Url of the page?
I personally found Google Analytics Content Experiments (and its predecessor Google Website Optimizer) to have more drawbacks than benefits, so I've started using straight Google Analytics + Amazon load-balancers like so: https://stackoverflow.com/a/12956940/470749

get a mutating url with javascript

i have the following question:
i'm currently working with a software(MicroStrategy, BI) wich has a functionality that exports reports to pdf, it works something like this:
each report has an unique ID, so you select the report to export, and with jsp i send this report's id to the exporting tool, and it generates a complete URL with some parameters that the MicroStrategy server will read to generate the PDF.
What i'm trying is to capture this pdf url and send it to a Java method that will save this pdf in the hard drive without prompting anything to the user.
My problem is that this URL doesn't generate instantly, it takes a while, AND, some redirections are made in the process.
So, after all that chitchat, how can i capture that damn URL?
What i'm doing is making the pdf load into an iframe, and then extracting the url with a js code i found searching, assigning it to a JSP variable, and then, once i have the pdf url, call the Java Method. But it is not working.
The JavaScript function is this:
<script language="text/javascript">
function getSrc()
{
var CurrentUrl = document.getElementById('miframe').contentWindow.location.href;
if(currentUrl.substr(length-5)==".pdf")
{
return currentUrl;
}
else
{
setTimeout(getSrc(),5000);
}
}
</script>
and this is the call i make to it:
<% jsp code
String currentUrl="<script>document.writeln(getSrc();)</script>";
more jsp code %>
The rest of the code is actually fine, tried it with a normal pdf URL and it saved the pdf into the disk.
Hope it is understadable, and thanks in advance!
Your main problem is that you are calling getSrc, not passing it to setTimeout (you are actually passing null to setTimeout, unless the second call to getSrc happens to work, in which case you are passing a string, which setTimeout can't process due to "syntax errors".
Instead, use setTimeout(getSrc,5000); - no parentheses after getSrc. This passes the function, rather than its result.
Also, currentUrl.substr(length-5) is wrong, partly because length is undefined (you need currentUrl.length in there), and partly because you need -4 to get the last four characters.
I don't know what kind of access you have to MicroStrategy, but there is a MicroStrategy java api that will allow you to execute the document and get pdf without capturing the url.
Check out their Knowledge Base for examples.
Why don't you just save the report/document with PDF format as default, in this way when you open the report it will automatically generated in PDF.
If you don't like the idea to save a report in PDF (for example because you need it also as regular report and you don't want to maintain two version of the same object), you can use URLAPI to generate the PDF using &executionMode=3 and &currentViewMedia=32.
Not sure about these parameters, the best way for you to figure out which they are (beside some MicroStrategy TN) is to export the report in PDF and check the url.

How to remove 'http://' from a URL in JavaScript [duplicate]

This question already has answers here:
taking off the http or https off a javascript string
(13 answers)
Closed 6 years ago.
I have run into an odd situation. I'm writing a JavaScript bookmarklet that will allow users to click and share external websites to our website very easily and quickly. It simply get's the title, page URL, and if they've selected any text on the page, it grabs it too.
The problem is it doesn't work with external domains for some reason, so if we use it internally we end up with a share window with the URL formatted like this:
http://internaldomain.com/sharetool.php?shareid=http://internaldomain.com/anotheroddpage.html&title=....
That works just fine, BUT if we try to use an external domain and end up with a URL formatted like this:
http://internaldomain.com/sharetool.php?shareid=http://externaldomain.com/coolpagetoshare.html&title=...
Then we get a Forbidden Error on our page and can't load it... If we manually remove the http:// from the externaldomain address, it loads just fine again.
So.. I'm thinking the best solution to get around this problem is to modify the JavaScript bookmarklet to remove the http as it's loading the window. Here is how my current bookmarklet looks:
javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://internaldomain.com/sharetool.php',l=d.location,e=encodeURIComponent,u=f+'?u='+e(l.href)+
As you can see, e(l.href) is where the URL is passed.
How can I modify that so it removes the external domains http://?
I think it would be better to take into account all possible protocols.
result = url.replace(/(^\w+:|^)\/\//, '');
url = url.replace(/^https?:\/\//, '')
l.href.replace(/^http:\/\//, '')
I think the regular expression you need is /(?:http://)(.*)/i. The first match of this should be it.
Try using replace function
var url = url.replace("http%3A%2F%2F", "");

How can I access the data from javascript by Qt?

I used webview to show the webpage,
view->setUrl(QUrl("C:\\Qt\\2010.07\\qt\\serbest\\googleSearch.htm"));
in the HTML code I put some ajax code googleSearch. After I execute the program, the webview runs and there are results (pages links).
When I clicked any of the links they do not open. So what do I do to open the links I clicked?
How can I access the title of the links from the result of javascript in Qt?
"C:\Qt\2010.07\qt\serbest\googleSearch.htm"
That's not a URL, it's a Windows pathname. Also, it has troublesome unescaped backslashes: \201 is a string literal escape for the control character U+0081 in many languages (including JavaScript as per your tags, though the snippet does not appear to actually be JavaScript).
The URL form of that filename would look something like:
"file:///C|/Qt/2010.07/qt/serbest/googleSearch.htm"
You can convert a filename into a URL using fromLocalFile().

Categories

Resources