Is there a way to make Omniture capture the url/page loaded via ajax as a "Load" event and not a "Click" event? - ajax

I am currently working on a Ajax based mobile website project and am not able to get Omniture to work correctly. Here is a brief detail of the problem.
Assume a mobile site which has multiple pages, like example.com/a, example.com/b, example.com/c, example.com/d, example.com/e, example.com/f, etc.
Each page of the site, has Omniture's code, like:
<html><head></head><body>
<script type="text/javascript" src="//domain-and-path-to-omniture-code-files/s_code.js">
<script type="text/javascript">
s.pageName = "blah";
// some other ... s.blahBlah ... properties here...
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code);
</script>
<div id="content">SOME CONTENT</div>
</body>
User opens the browser and opens one url/page, like example.com/a
The page (example.com/a) has multiple links to the content on the same page, like #topic1, #topic2, #topic3, etc. and also has links to other static pages of the site, like example.com/b, example.com/c, example.com/d, etc.
I use jQuery to control click events on these links.
When user clicks on a named link, like #topic1, #topic2, etc., the page is animated/smooth-scrolled to the target element/content-section; and Omniture's "s.tl()" function is triggered, to track/capture the click event with relevant/required details.
## THIS IS THE PROBLEM AREA ## When user clicks on a link to a different static page, like example.com/b, example.com/c, etc., instead of allowing the browser to do a full page-load, the Ajax version of the target page is loaded into the content holder (by Ajax version, I mean to say that the page only has bare-minimum markup/content and not the entire html/head/common-css/js includes/etc).
Now the problem is that, when the page is loaded normally, Omniture captures it correctly as a "Load" event, but when it's loaded via JavaScript/Ajax, Omniture captures it as a "Click" event!
The Ajax/version of the page, does not include Omniture library "s_code.js" JS again (for obvious reasons, its already there on the parent/main page). Along with the required content, this page only has a script-tag, which sets required "s.blahBlah" values for the new page and the call to "s.t();".
I also tried to keep the Omniture code separate, in a common JS file, which is already loaded with the parent page, and only set the required "s.blahBlah" values in the Ajax call/function (which is also in a global/already loaded JS file), but still Omniture captures it as a "Click" event.
// s.tl(); ... gets captured as a click event
// s.t(); ... on normal page load... gets captured as a load event
// s.t(); ... after DOM-ready/page loaded via Ajax... gets captures as a click event
Any ideas! How can I make Omniture capture a load event? Is there a function like "s.l()" or something to trigger Omniture's "Load" event on demand.

The problem was not Omniture capturing it incorrectly, it was the tool "Omnibug", which I use to see the requests.
Omnibug 0.5.448 logs all "s.t()" calls made before page load event as Omniture "Load" event and any "s.t()" call made afterwards is captured as "Click" event.
Apparently, I was not the only one facing this issue. Others had already reported this to the developer of Omnibug (https://github.com/simpsora/omnibug/issues/4) and a fix has been made by him/a new version Omnibug 0.5.500 has been released.
The new version of Omnibug 0.5.500 captures all "s.t()" calls as "Load" events correctly and all "s.tl()" calls as "Click" event.
Thanks!

Related

Google Analytics on AJAX pages

I need to track visits of page that loads via Ajax. I'm currently using the latest HTML5 Boilerplate Google Analytics snippet (as of September 2017):
<script>
window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;
ga('create','UA-XXXXX-Y','auto');ga('send','pageview')
</script>
<script src="https://www.google-analytics.com/analytics.js" async defer></script>
For example, the page that I'm calling via Ajax shows as an overlay popup and does not update the URL in the address bar. It comes from a directory like this:
www.mysite.com/ajaxpages/popup.html
Do I need to place the entire Analytics snippet on the popup.html page? Do I have to update it? Google's documentation says I need to update my code to something like:
ga('set', 'page', '/new-page.html');
ga('send', 'pageview');
It seems fairly simple but I'm not exactly sure how I need to update the tracking code I'm using.
You do not need to put the entire analytics snippet in the popup page. In the function that loads the Ajax popup locate the bit that checks for the ajax success event and paste your second snippet in there; this will set a page path (so every subsequent call will use the new url) and the pageview call will send the updated information.

jQuery mobile - after browser refresh page totally messed up

I'm developping a jqm application with spring mobile in the back-end.
Whenever I hit the browser refresh button on my mobile phone the page is completely devastated afterwards. Browsers back-button works properly.
The data are still available due prg pattern (flashAttributes in Spring) after refresh. Only the view is malformed.
Any ideas how to solve this problem?
From jQuery Mobile docs :
The simplest approach when building a jQuery Mobile site is to reference the same set of stylesheets and scripts in the head of every page. If you need to load in specific scripts or styles for a particular page, we recommend binding logic to the pageinit event (details below) to run necessary code when a specific page is created (which can be determined by its id attribute, or a number of other ways). Following this approach will ensure that the code executes if the page is loaded directly or is pulled in and shown via Ajax
So what happens is - in jQuery Mobile, the scripts and styles defined in the head are loaded only once. So, in normal conditions, it works fine, as all the pages will use the scripts loaded from the first page.
But. When you refresh a page in-between, it triggers a page-reload instead of the ajax navigation model thatjqm uses. So all the scripts and styles loaded from the first page will not be included from here on out.
What you need to do is "reference the same set of stylesheets and scripts in the head of every page", so that even if you hit refresh in the middle, the scripts and styles that had been loaded from the head of the first page are loaded again.
I recommend you read the docs from the above link fully to gain a better understanding.

Facebook like button's iframe not expanded after ajax request

I'm adding a facebook share button to each post on a Wordpress (Using Facebook Share Button New plugin), it works ok for each post/page except when i'm loading them trough ajax, the result it's a normal Facebook like button but the popup (to write a comment) appears inside the button it is not expanded.
To check go to: http://iwanttobeher.com/ and then click on any face at the bottom of the page, then test the like button and you'll see what happens.
I don't know what to do, i tried to FB.XFBML.parse() after loading the content but the result is the same.
Switching to HTML5 didn't help in our case. What did was to remove the FB object just prior to new content being inserted into the page via Ajax:
delete FB;
wrapper.html(response.data);
We reload full pages via Ajax and so new page content recreates the FB object and re-initializes XFBML anyway. Not sure if this workaround would work if we reloaded only parts of the page though.
The original answer is here.
I've managed to fix it by changing the implementation to HTML5 instead Iframe or XFBML using Facebook's tool to generate like buttons: https://developers.facebook.com/docs/reference/plugins/like/

Load link,href,hyperlink,url in a lightbox or a frame on the current page with refresh the whole page

I am new to AJAX,
I want to have a javascript that will make all the link(include webpage,internal link, external link) load in a lightbox when clicked. Just like Facebook, when you click the photo, it will give you a frame , without redirect you to the photo page.
Overall, I want my user to click on ANY link of my website do not redirect to a new page which need to refresh the whole page.
I want the link to be load in a frame on demand, also know as AJAX right?
Actually I just want to know this technique is called as what?? Any google search term ?? searching queries??
Any recommend article or tutorial to do this?
AJAX: Asynchronous JavaScript and XML. Your example isn't AJAX, but rather it's using JavaScript to do event binding that causes actions to take place in response to events made by the user in the browser.
You could use jQuery to bind an event to all the links of a certain type on a page. The exact implementation will depend on your HTML markup.
If, for example, you have several images wrapped in link tags:
<img src="image1.jpg" />
<img src="image2.jpg" />
You could have jQuery similar to the following (be sure to load jQuery prior to this in the page):
<script>
$('.image_link').click(function(event) {
event.preventDefault(); // stops it from doing normal link action
// and then down here you'd need JS for your lightbox library
});
</script>
Smashing Magazine has an article that might help you: Modal Windows in Modern Web Design.

Event handler for location.hash changing?

I have a Flash document viewer embedded in my page, where the user can view the preview version of the document, and then purchase the full version if they like. Is it possible to have a hyperlink in the document itself "BUY NOW" which would command the browser to do something on the current page without having to refresh?
I'm imagining something like:
www.example.com/currentpage.php#buy
...as a link in the embedded document, which would in theory scroll to a position in the parent web page. Are there any mechanisms, maybe event handlers where I can run some js upon being directed to the "#buy" anchor?
EDIT: I just discovered Javascript has a
window.location.hash
object that I can check, but I don't want to poll for it, the question remains if there are any mechanisms or events to detect it changing?

Resources