HashTagChanged event not firing

In the Open event for a page I place this:

Session.HashTag = Session.ShortPageName

ShortPageName is shortened page name.

In the Session.HashTagChanged event I have:

MsgBox "HashTag changed: " + self.HashTag

The changed HashTag is showing up in the address bar but the HashTagChanged event isn’t firing.

I’m not sure if thats by design or not - I could see it either way.

If you are using that event to determine when you need to change the UI I recommend abstracting that out. Create methods to change the UI then use the HashTagChanged event as one way to call those methods. That way when you set the HashTag you can still adjust the UI at the same time without being dependent on the hashtag.

Changing the hashtag from inside the app indeed does not trigger the HashTagChanged even. But if changed in the web browser or through a link, it does fire fine. I have been using that event to pass back JavaScript variables to Xojo before I earned how to use WebDSK and it worked fine as well.

If you need to monitor every HasTag change including from inside your coed, you could use a timer.

I was just using HashTagChanged event to make sure it was changing (but it changes in the address bar so don’t really need it for that purpose). I thought it might be a Xojo glitch; apparently it is not a Xojo glitch but I don’t know why it’s not.

I also thought this was explaining why HashTags are not getting sent to Google Analytics. Let me explain. I want to send tracking data to Google Analytics via hashtags using this method. It uses the location.hash in the Javascript for the Google Analytics Tracking Code. The tracking code is in the App.HTMLHeader.

Michel - I changed my mind about tracking only first and last pages because there is no way for user to navigate to a specific page anyway. I realized today that Xojo “pages” aren’t really pages (thanks to Phillip Z description here).

Do I need to put the tracking code on every “page”?

[quote=116175:@Ken Gish]Michel - I changed my mind about tracking only first and last pages because there is no way for user to navigate to a specific page anyway. I realized today that Xojo “pages” aren’t really pages (thanks to Phillip Z description here).

Do I need to put the tracking code on every “page”?[/quote]

There is a way to link in HTML to WebPages inside a web app through hashtags, allowing pretty much the same easy navigation as through HTML pages. Basically, what you do in HashTagChanged is something like :

Select Case session.hashtag Case "toto" totowebpage.show Case "Dorothy" dorothy.show

And in your index.html you put links like

http://mydomain.com/cgi-bin/myapp.cgi#toto

So you can link in HTML to every WebPage in your app and present it to the user the same way an HTML site would. In order to keep navigation logical, I think it is good to keep a link to the index page in the upper left corner of the screen as most sites do.

Now, I am not sure the blog method you are mentioning would work on a web app. Google cannot see the HTML inside the WE itself, because it cannot run the web app. So only the JavaScript will be able to signal Google Analytics where the user is.

So as I told you, it is easy to navigate between pages of a web app through the HashTags. Now what that means is the usual architecture of navigation within the app becomes less rigid and you need to conceive your app accordingly. For instance, in a regular web app, the default WebPage is the mandatory landing page. When the user is allowed to enter through another WebPage, you need to make sure all possible session variables are already initialized correctly. Also, the logic of the app becoming more horizontal some authoritarian designs become imposible, such as binary navigation choices.

Altogether, though, I consider such a model as just as interesting as a multi-window app where the user can click between windows.

As I pointed out in a previous thread, a web app will never be exactly the same as an HTML site. But it can offer to the visitor a navigation experience just as fluid.

Hope I did not confuse you too much :wink:

Jump table !!!

dim w as WebPage = jumpTable.lookup( session.hashtag, nil )
if w <> nil then w.Show

set the thing up once & yer off
and you can add & remove pages dynamically

have fun !

[quote=116191:@Norman Palardy]Jump table !!!

dim w as WebPage = jumpTable.lookup( session.hashtag, nil )
if w <> nil then w.Show

set the thing up once & yer off
and you can add & remove pages dynamically

have fun ![/quote]

Is this using a dictionary such as described here http://documentation.xojo.com/index.php/Dictionary.Lookup , with windows inside ?

I tried that and it works fine. Of course I would need to make the dictionary global to access it from everywhere, add and remove pages dynamically.

[code]Sub HashTagChanged()
Dim jumpTable as New Dictionary
jumpTable.Value(“toto”)= totowebpage
jumpTable.Value(“dorothy”)= dorothy

dim w as WebPage = jumpTable.lookup( session.hashtag, nil )
if w <> nil then w.Show
End Sub
[/code]

Thank you :slight_smile:

JumpTable seems like the right way to go but please clarify how you are setting that up.

Just To Clarify: In the app I am working on, we cannot have the user navigating to whichever page they want to. We want everyone to navigate the same way (except that users can quit whenever they want to). I know it’s boring but it’s not a web site, it’s a Desktop application that we are converting to a web app.

Users have to proceed from one specific “page” to the next ?
I’m not quite clear on what you mean by “we cannot have the user navigating to whichever page they want to. We want everyone to navigate the same way”

All the jump table does is give you a nice quick easy way to associate a specific “key” (in this case a string) with a specific page to go to based on that key

[quote=116195:@Michel Bujardet]Is this using a dictionary such as described here http://documentation.xojo.com/index.php/Dictionary.Lookup , with windows inside ?
[/quote]
Yes
Because the keys and values are variants you can stuff in whatever you want :stuck_out_tongue:

There’s lots of fun things you can do with dictionaries, arrays, variants & delegates :slight_smile:

Just trying to send tracking data to Google Analytics via hashtags. Doesn’t seem to be working.

I thought the ExecuteJavaScript was working with Google code ? Why go for HTML ?

I am sorry for the confusion. Let me explain.

ExecuteJavaScript is working but that method means I would have to put the tracking code on every WebPage I want to track. If I can’t get the tracking code to work in HTMLHeader then this is what I will have to do.

What has changed is that I realized there would be no way for someone to navigate to a specific WebPage via a Google Search (which would be bad in my case). So, I want to track every WebPage, if possible. The HTMLHeader seemed like the way to do that. Perhaps I should be using PrepareSession?

What I am hoping to understand by tracking each page is how users are exiting the app (for example, they are getting hung up on page and then quitting), how long it is taking to complete each page (or at least get to a certain spot in the app), and what choices they make (which alters the navigation slightly). I realize I could code this into the app but GA is so much easier to use plus I want to share the analytics with other people.

[quote=116296:@Ken Gish]I am sorry for the confusion. Let me explain.

ExecuteJavaScript is working but that method means I would have to put the tracking code on every WebPage I want to track. If I can’t get the tracking code to work in HTMLHeader then this is what I will have to do.

What has changed is that I realized there would be no way for someone to navigate to a specific WebPage via a Google Search (which would be bad in my case). So, I want to track every WebPage, if possible. The HTMLHeader seemed like the way to do that. Perhaps I should be using PrepareSession?

What I am hoping to understand by tracking each page is how users are exiting the app (for example, they are getting hung up on page and then quitting), how long it is taking to complete each page (or at least get to a certain spot in the app), and what choices they make (which alters the navigation slightly). I realize I could code this into the app but GA is so much easier to use plus I want to share the analytics with other people.[/quote]

HTML will not work because Google does not see your WebPages. So it is JavaScript. But you still have a possible issue : in the analytics.js code I just gazed upon quickly, there does not seem to be any specific marker for each page, unless I overlooked it. If you cannot indicate to Google the name of the page or something, it will just go by the URL, which does not change in a web app when webpages change. So it is very possible that even if you execute analytics.js in every webpage, Google will consider your app as only one page.

I would try to execute analytics.js in two WebPages and see if GA has been able to distinguish between the two, first. If that was the case, then you generalize it to all your pages. Otherwise, you can still fall back to internal tracking.

Just tried overriding default values and it seems to work. Described here:

https://developers.google.com/analytics/devguides/collection/analyticsjs/pages

Here’s an example from the tracking code that sends page information:

ga(‘send’, ‘pageview’,{‘page’: ‘/"+Session.ShortPageName+"’,‘title’: ‘"+self.Name+"’});

So, unless someone points out a better/easier way to do this, I will just add this to the tracking code for all the pages I want to track.

[quote=116313:@Ken Gish]Just tried overriding default values and it seems to work. Described here:

https://developers.google.com/analytics/devguides/collection/analyticsjs/pages

Here’s an example from the tracking code that sends page information:

ga(‘send’, ‘pageview’,{‘page’: ‘/"+Session.ShortPageName+"’,‘title’: ‘"+self.Name+"’});

So, unless someone points out a better/easier way to do this, I will just add this to the tracking code for all the pages I want to track.[/quote]

Seems fine. As you will be able to identify each WebPage by its name and title, you are just a few paste away …

Yeah, I admit I am being a little lazy. It just seems like there has to be a better way.

Thanks for all your help.

So the problem (if you’re not aware) is that Web Pages dont “load” in the traditional sense of a web page. All of the information for each “page” is loaded in the background and just displayed.

Having said that, adding the Google analytics to the HTMLHeader doesn’t get you very far because the code will still only load once because the html head portion of the only loads once.

You may be able to do what you want with a WebSDK control. Use it to get the Google code onto the page (in 2014r2, you can get it directly into the HTMLHeader) and then just place your control on every page that you want to track. I’m just talking off the top of my head here though. I seem to remember that Google doesn’t track individual hashtags separately. Their examples for tracking Ajax apps suggest using real URLs in a site map file and then have your web server convert them back to hashtags.

[quote=116354:@Greg O’Lone]So the problem (if you’re not aware) is that Web Pages dont “load” in the traditional sense of a web page. All of the information for each “page” is loaded in the background and just displayed.

Having said that, adding the Google analytics to the HTMLHeader doesn’t get you very far because the code will still only load once because the html head portion of the only loads once.

You may be able to do what you want with a WebSDK control. Use it to get the Google code onto the page (in 2014r2, you can get it directly into the HTMLHeader) and then just place your control on every page that you want to track. I’m just talking off the top of my head here though. I seem to remember that Google doesn’t track individual hashtags separately. Their examples for tracking Ajax apps suggest using real URLs in a site map file and then have your web server convert them back to hashtags.[/quote]

Google indeed does track pages whatever the hash tag. And does not “see” html inside a web app because it cannot get there through a link. The best approach is though the js script.

Thanks Greg and Michel for clarifying the HTMLHeader issue (I apologize that this original issue morphed into Google Analytics).

I will keep the WebSDK control idea in mind.

After looking at the analytics this morning, I can confirm that it is tracking all of the Session.ShortPageName values which overrides the page parameter in above code snippet. I am still using HashTags to display Session.ShortPageName in the address bar but this is just for troubleshooting with users, not for tracking (which doesn’t work because HTMLHeader only loads once).

I am not certain about this, but I think Google Analytics is treating hashtags differently. I had hashtags for two pages working all day yesterday and none of the hashtags are showing up in the analytics.

Also, it wasn’t as bad as I thought it would be to add the analytics to every page because most of the “pages” are just based on one WebPage which gets reused.

Thanks again for the help.