Button as a fake link for a Google Analytics funnel - javascript

I'm trying to set up a funnel that has a final step of clicking on a button and downloading a document. Since I can't track the button, I was hoping to set up a fake link that doesn't redirect the user anywhere but allows Google Analytics to see how many people clicked on the button.
What I have is this Javascript piece of code but when it gives me an error:
<a href=”/goal/example” onclick=”javascript:pageTracker._trackPageview (‘example’);”target=”blank”>
Or, if this doesn't work at all, is there any other way to add a button to my funnel?
Thanks!

To piggy-back on #nyuen's answer, (though without your error message it's hard to know what's wrong), it looks like your link could be improved as well. First, since it sounds like you'd rather it not link anywhere, I'd set the href to your code rather than the onclick. And second, if you don't want it leading anywhere a target="blank" is going to be annoying. (Also I assume your <a> is closed eventually). Try:
[...]

There's a couple things wrong with the code looks like. Try this:
onclick="_gaq.push(['_trackPageview', 'example'])"
The javascript part is optional, and also the quotes need to be straight quotes, not the 'smart' quotes.

Related

Script In Formula Text Search Result

I have a search result column where I'm using the record ID to pass parameters as a link to a non-netsuite external site I own that is designed for a specific non-NetSuite task.
The link is working great and the formula looks something like this:
'Use Tool'
However, I'd like to add some script to it by using onClick, and each time I've tried this either I get back invalid expression or the script seems to get stripped out of the link.
I've added what should just be a simple alert window with the record id as a test like this:
'Use Tool'
but using the dev tools to inspect this the search result shows up like this:
Use MT Tool With Tracking
I'd like to track something simple like which user clicked the link and what day it was, but I'm starting to think that this might not be possible.
Has anyone ever tried doing something like this before?
Is there a better way to do this?
Thanks in advance for any help.
It may be a rudimentary attempt on NetSuite's part to prevent XSS attempts, but if you don't need to support Internet Explorer you can get around it using the template literal syntax.
'Use Tool'
I still think the escaped double quote is a problem ☺, but I was able to duplicate your issue in preview mode (I think it's a result of NetSuite's whence parameter). Run or Save and Run does not encounter the issue. See screenshots of Search Formula Text fields below and corresponding elements when run.
Lazy Loader
Result
Element

Javascript: Redirecting to another site through a popup

I'm quite bad with Javascript and I can't work out a solution I need help to. I'm having a website and I'm trying to make a redirection to another site, but through a popup.
Example :
<script>alert(This will prompt up the message)</scrip>
<script>window.location="http://This-will-redirect-me-to-another-link.com";</scrip>
Like you can see I could simply use the second javascript to redirect the persons to another page, but due some reasons I can't use it as it will work only for half of the page(the script would be kinda 'sandboxed'), but if I'd make a popup(the first alert script) the second script would get out of the 'sandbox'. Is there anyone who has any ideas how I should implement this or can it be done otherwise with PHP or HTML?
I'm having a MyBB forum and there's a shoutbox for it which I'm using. There's a command which will change the notice of the shoutbox and the command is as such /notice New notice | But I noted that the new notice can be changed with javascript and it'll work such as /notice js code here | Then I thought that what if I would make such a javascript that would redirect people to another webpage. As I'm having such a forum where it's needed to redirect from the main page to another one, I'd like to apply it. Then Staffs could do it in the forum very well, but there's a problem. by adding
/notice window.location="http://This-will-redirect-me-to-another-link.com";
It'll affect only the shoutbox and shoutbox is being redirected to another webpage, but as an alert works for the whole forum I thought maybe I can redirect them to somewhere else with the alert. I want to know is it possible with just one script then Staffs would be able to do it. I know it's a serious security risk & it can be otherwise also, but I'd really like to experiment with it.
I hope someone can help. :)
Try:
window.open('url to other site', 'window name', 'width=900,height=650,scrollbars=yes');
If I understand you (if not please correct me), you can put a tag on popup or another place:
<a href="http://another.site.com/"
onclick="return confirm('Do you want to see another page?');">Redirect</a>

Search engines and javascript code on click of a hyperlink

I create a HTML link like this.
<a href='http://www.mywebsite.com/aPage' onclick='customFunc(); return false;'>Show Info</a>
I'm writing an ajax functionality (in customFunc) when this link is clicked and displaying data which is same as the data shown by the link in HREF tag.
Question: When search engines see my link, will they cache it? Or will they get an impression that I'm trying to do a false magic to get this page cached, and hence ignore it?
Appreciate your suggestions.
Edit: So what I interpret from this Q & A is that, (theoretically) search engines are just bothered about the href, and since it found one in the above link - it will cache this page without any troubles and it won't be worried about the things I do in the onclick JS call.
If anyone has a different opinion, please do add your comments.
Spiders will automatically follow each anchor in your page. If you want to avoid this behavior you have to specify rel="nofollow" for "a" tags you want to skip. You can also avoid indexing of whole pages using meta tags or robots.txt.
Anyway attached event listeners are theoretically irrelevant to search engine... I took a look the SEO guide lines from google here: http://www.google.com/webmasters/docs/search-engine-optimization-starter-guide.pdf and I did not read about a scenario like your.
Although search engines like Google now interpret some javascripts, in this case, it will clearly see the href and not see the rel="nofollow".

Understanding "javascript : ... ;" inside <a href=" ">

What is the meanign of javascript:; that is kept inside the href attribute in an link?
Like
Link
IF you need to pass a javascript snippet which needs to run instead of the default behavior of an element then you use this javascript: ; syntax.
For example
Test <!-- Runs on the click of the link -->
Similarly, you can combine these on other events also, like onclick, onchange etc but this is really not necessary, since you can execute the snippet, directly.
The uses of this, i have seen in years are:
Test
<form action="javascript:void(0);">..</form>
The javascript:; in the href does the same as putting something in the "onclick" property.
Thus,
Link
is identical to
Link
I'm not sure which is better to use when, but worth mentioning is that you can type these "links" in to the address bar of most modern browsers and it will run.
copy and paste (or type, chrome seems to prohibit this.) in to your address bar
javascript:alert("test");
as well as you can save links with these addresses to bookmarks so that it will run that script on any page you click the bookmark on.
That alone does nothing, but normally javascript: precedes some JavaScript code to indicate that the browser should execute the code instead of treat the href attribute as a URL. Thats it.
This might be intended as a reference that does nothing when clicked and might be accompanied by setting onclick etc. to actually do anything.
upd: While some say that putting a script in href is the same as putting it in onclick, there are some differences, like what happens on right click (and some scripts definitely should not be opened in a new tab or such). Still, my opinion of the practice is that it is somewhat ugly, and not only because of uninformative text in status bar when mouse over the link.
You can imagine that as someone copying that "javascript:;" into the url box and hitting Enter. Since it starts with "javascript:" the browser will know to execute what follows as javascript in the current page. Since all that follows is a ";", nothing will happen, actually. That's the same as clicking a button that has a onClick attribute set to ";".
For example:
Click me!
has the same effect that
<button onClick="alert('howdy!')">Click me!</button>
or even
Click me!
Keep in mind that, since it's a link, most browsers will render its address (in that case "javascript:alert('howdy!')") in the status bar, and that may be undesired (I find it to be particularly ugly).

HTML/JavaScript Linking

This question may have been asked before, but I had trouble finding an answer, since I didn't quite know what search terms to use.
In HTML, how do you make a link go a place, but execute JavaScript instead when it is clicked? Right now, I have a link that's somewhat like this:
Stuff
But, the thing is, when someone right clicks the link, I want them to be able to copy a direct URL to the link. Also, if someone's browser does not support JavaScript, or they have it disabled, I would still like them to be able to reach the page. Is it just
Stuff?
Or is there something more complicated?
Thanks!
Stuff
Make sure that the dosuff function returns false if you want the link to not be followed when the script runs.
(The 'javascript:' is pointless. It labels a loop, but you don't have a loop. See the HTML spec for how to specify which language is being used in the intrinsic event handler attributes — better yet, use unobtrusive JavaScript and progressive enhancement).
You need to let the event return false to block the default action.
<a href="http://example.com" onclick="doSomething(); return false;">

Categories