Code a Web Analytics Tool - javascript

I am trying to capture click events in my existing Java/J2EE intranet application.
The application has been in production and we are trying to add this feature.
In order to accomplish this; we've created a javascript function which sends the required data in the form of Ajax call to server and we've able to capture the required data.
However, in order to implement this, we had to manually add javascript calls via onclick events to places from where we wanted to capture data.
This includes radio , submit , menu clicks ,etc. Is this approach of adding onclick tags to respective controls correct or is there a smarter way to handle this?
We're a bit resistant to use a tool for this considering some compliance directives.
Sample onclick call:
onclick="footprint.trace('CLK_REGISTER_BTN');validateForm();"

<script type="text/javascript">
$(window).click(function(e) {
alert(e.target.id); // gives the element's ID
alert(e.target.className); // gives the elements class(es)
});
</script>
Above code resolved my query. I was able to get all click events on page which are super set of button clicks and hence able to action accordingly.

Related

How to track when a Radio button is clicked in Google Tag Manager without clicking the submit button/moving on from the page?

I've a pretty simple question but its been bothering me for a few days now. I want to track when someone clicks a radio button as a trigger or click, essentially to track the click and pull the data I need even if they haven't clicked submit or moved off the page. I just want to be able to do it when its clicked on the page but I can't seem to get my head around it in Google Tag Manager.
I ended up coming up with this so far but its pulling all clicks.
My solution was to create a custom variable that isolates the radio button by its class using Query Selector, then create a tag that fires on all clicks. The issue is that this is bringing back way more data than I need. It is bringing back random clicks on the page.
I tried to set it up in google tag manager as Some clicks, then set it to My Radio Variable - Equals - True but this didn't bring back anything at all.
My Radio Variable:
function () {
return document.querySelector('[class="radios__input"]:checked').id
}
I'm still new to this so any help would be greatly appreciated, thanks in advance.
This might require not only the variable.
Now you can get the id from the radio element which is great.
But you said it is returning a lot of other element you don't need so looks like it is lack of the trigger setting.
Trigger should be the important one in this scenario.
You can narrow down the range to only the radio element you want to track.
Like configure the trigger to
Click Element , match css selector , {Your special css selector to the radio button}
If you are not familiar about the above I mentioned. You can attach some screenshots about what is your trigger and variable and how you use it in your GTM.

In Salesforce open the edit screen after the object was created with Javascript button

In Salesforce, we have a button that creates events with the fields already filled out, but after the item is created I want it to reload the screen in the "Edit" view in case they want to change anything. Any ideas?
Do you need to validate fields values? Maybe it will be easier to do with field validation rules? It can be useful in cases when your data is populated not only from user screens, but also can be created in code (classes/triggers) or via API.
If you know that you exactly should to use JavaScript, you can add standard event attributes to command buttons on your Visualforce page and write JS functions for implementation of your validation logic.
I ended up creating a visualforce page with a controller and a custom button to accomplish what I needed.

Redirect to link via workflow button click

I have added a button via workflow and I need to redirect it to another location/link(say .. www.google.com link). How can I achive this, Since button's id cannot be changed in workflow, I could not append any Javascript function in that button . Also Action in workflow does not have an option to set link to Workflow buttons,.
Does this mean Workflow buttons can only be made to move to another State?
Note: I know to add buttons via user script but for this particular scenario I want to achive this only with workflow button.
The only way to handle button clicks in workflows is to create a transition to another state. Within the transition, there is a drop-down field called Button that lets you choose which button would fire the transition.
You can only cause a workflow to navigate to either a record using the Go To Record action, or a task link using the Go To Page action. But I'm not sure if you could navigate to a link using workflows as you've mentioned above.
Why not add a button and hijack it via a client script? Just add a call on the form of client side to find the button element on the DOM and change the properties. This can be easily done with jQuery, which comes by default on NetSuite.

Adding web content dynamically with jquery and jstl in a Spring-MVC app

I'm developing a control panel web app. Now, i have to do an edit user window in order to add or delete roles of the user. I'm thinking in many ways to do it so i would like to ask you how i can afford this in the simpliest way and respecting good practises.
The jsp view has a select with available roles for the user. When you click an option a new div element with a button, rolename and role description has to be displayed. I catch the event with jquery but i have some doubts:
1- How can i pass the username to the jquery function? i'm using jstl but it´s server-side and javascript client-side. Maybe.. i have to do.. /admin/userRoles/john and get the user from the url? Or set a var with jstl? I read about get an attribute model mixing jstl and javascript but it doesn't seem a good practise...
2- Continuing with the jstl and javascript... When i click a select option to select a new role i need to create a new div with the role info (role name, role description,...) and a button to delete the div. I have a jquery function which captures this event and disable the option of the select. How can i manage to refer the div to the role in order to enable the option if the delete button is selected?
Maybe i have to set the div id with the rolename?
4- The div has a button with a text (delete) but i need to translate it depending on the language. How can i get the translation?
thank you (i will check the most useful answer and vote up the others)
How can i pass the username to the jquery function?
Just reference nomrally using EL
<script>
var yourJsVar = "${yourUsernameVar}";
<script>
2,3,4 don't fully understand the question.
You can map spring forms to pojo's easily. Or alternatively submit and return data using Ajax and json, which is also made easy by spring-mvc and jackson. The choice of how you do this CRUD is up to you.

How to store URL of clicked hyperlink

I am displaying a warning dialog box whenever user tries to navigate from current page without saving data on current page. Its working fine now I want to call a function (Spring controller, its kind of java function which handled URL mappings ) when user clicks on Ok (in warning dialog box) and then he should get redirectd to desired page.
Let me try to make it simple (Its confusing for me also):
User is on registration page, he/she made some changes and didn't save it.
Now user clicked on any other link for example he clicked on About Us link.
Now I want to execute my spring controller.
After execution of controller user should get navigated to About Us page.
For this I need to save value of clicked hyperlink and pass it to my spring controller.
So how can I store URL of clicked link (URL of About Us page in above example) ?
PS: I will really appreciate if anybody can edit my question to make it easier to understand.
if you use jQuery, you can attach an event handler to onclick to all links in the page and once clicked the handler should save the href attribute to some variable. then create a onbeforeunload event listener on your window, where you can use the value however you want, call your controller or save the value in a cookie or something.
Are all the links on the page pointing to your spring application? If there are no external links anywhere (pointing to external resource) - then you could write a simple Filter where you can save the requested page into the session.
Otherwise, if there are links to external resources - you would need to rewrite them from www.external.com to www.my.com\MagicController?requestedPage=www.external.com. Controller will save the link and send a redirect in HTTP header to the requested page. This is a common practice - even google does that (check out the google search result links for how it will look like).
Added: Weird, but google does that only on some rare occasions, so you probably won't be able to find an example there.
Don't require to preserve the href of selected tab.Do one thing attach same javascript function with each tab and pass the "this" as parameter of function.
Function of the javascript is
function Attach(ele)
{
// 1. Find the handle of selected tag and store in the variable.
ele=$(ele);
// 2. Find the value of href
var href=ele.attr("href");
// 3. Perform server side operation you want.
// 4. redirect to another page.
window.location=href;
return false;
}

Categories

Resources