Google Analytics

Want to post something that doesn't quite fit into the other forums? This is the place for that.
dsfh2992
Posts: 153
Joined: Tue Oct 06, 2015 9:57 pm

Google Analytics

Postby dsfh2992 » Wed Oct 21, 2015 12:22 am

Any guidance on best practices how to incorporate Google Analytics onto a Virtual Radar site?

Thanks,
Dan
adsbexchange.com

agw
Posts: 1896
Joined: Fri Feb 17, 2012 3:20 am

Re: Google Analytics

Postby agw » Wed Oct 21, 2015 2:12 am

The easiest way would probably be to use the custom content plugin. Create an HTML page that just has the script tag that Google give you and then add an entry to the custom content plugin with these settings:

Inject file: <FULL PATH TO YOUR HTML PAGE>
At: END of BODY
Address: *

That will add the script to the end of every HTML page that gets served by VRS.

dsfh2992
Posts: 153
Joined: Tue Oct 06, 2015 9:57 pm

Re: Google Analytics

Postby dsfh2992 » Wed Oct 21, 2015 6:40 am

Thanks. That seemed to work perfectly!

--Dan

dsfh2992
Posts: 153
Joined: Tue Oct 06, 2015 9:57 pm

Re: Google Analytics

Postby dsfh2992 » Thu Oct 29, 2015 5:10 am

I don't want to push my luck here, but it seems that when users spend a long time looking at the desktop VRS page, Google no longer tracks them.

If I wanted to embed the Google tracking code in the "details" section, so it was updated each time they clicked on a new aircraft, is that possible, and what file should I be looking at to accomplish this? (the goal is to track how long they're actively using the interface).

Thanks,
Dan

agw
Posts: 1896
Joined: Fri Feb 17, 2012 3:20 am

Re: Google Analytics

Postby agw » Tue Nov 03, 2015 10:56 pm

Embedding it into the details panel wouldn't have the effect you're looking for, the details panel isn't an iframe, it's just HTML that gets built up by a jQueryUI plugin. Also if the user has automatic selection switched on, which it is by default, then a change in the aircraft displayed in the panel doesn't mean that they selected the page.

However - it seems that you can send messages to the analytics object to tell it that the user changed a page (https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications). The aircraft list object raises an event when the selection changes, and you can ask the aircraft list if the selection was made by the user or by the code. The script to hook that and to send a fake page with, say, the aircraft ICAO when the user selects the aircraft would be something like this (I've not tested it but it should be along the right lines):

Code: Select all

<script type="text/javascript">
    if(VRS && VRS.globalDispatch) {
        // Hook the event that is raised when the bootstrap starts up
        VRS.globalDispatch.hook(VRS.globalEvent.bootstrapCreated, function(bootStrap) {
            // Hook the event raised when the page has finished initialising
            bootstrap.hookInitialised(function(pageSettings) {
               if(pageSettings.aircraftList) {
                   // Hook the selection changed event
                   pageSettings.aircraftList.hookSelectedAircraftChanged(function(aircraft) {
                      if(pageSettings.getWasAircraftSelectedByUser()) {
                          // Call Google Analytics and tell it that the page has changed.
                          // Use the aircraft's ICAO as the name of the new page.
                          ga('set', 'page', '/' + aircraft.icao.val);
                      }
                   });
               }
            });
        });
    }
</script>


I'm not sure if that alone would be enough to update the "time spent" counter on the page, but it's probably a good start :)

dsfh2992
Posts: 153
Joined: Tue Oct 06, 2015 9:57 pm

Re: Google Analytics

Postby dsfh2992 » Wed Nov 04, 2015 6:02 pm

OK, I will check into that. I found a way to "ping" the analytics page from the details page, so I've been going that route for now. You are correct though, that if auto-select is on, we won't know if it was a manual click....

loww
Posts: 90
Joined: Sun Jun 28, 2015 10:55 am
Location: LOWW
Contact:

Re: Google Analytics

Postby loww » Sat Nov 07, 2015 9:15 pm

G A is bad for privacy. :evil:
:!: :!: :!: I search for People who want exchange VRS Data. I life near LOWW and i have a huge Coverage and multiple Receiver. :!: :!: :!:
My newest Project: http://www.publictransportforum.at/

ernieek
Posts: 11
Joined: Tue Aug 01, 2017 9:12 am
Location: Tilburg - NL
Contact:

Re: Google Analytics

Postby ernieek » Tue Aug 29, 2017 10:19 am

hello,

did you get it working??

I get an error on the script

<script type="text/javascript">
if(VRS && VRS.globalDispatch) {
// Hook the event that is raised when the bootstrap starts up
VRS.globalDispatch.hook(VRS.globalEvent.bootstrapCreated, function(bootStrap) {
// Hook the event raised when the page has finished initialising
bootstrap.hookInitialised(function(pageSettings) {
if(pageSettings.aircraftList) {
// Hook the selection changed event
pageSettings.aircraftList.hookSelectedAircraftChanged(function(aircraft) {
if(pageSettings.getWasAircraftSelectedByUser()) {
// Call Google Analytics and tell it that the page has changed.
// Use the aircraft's ICAO as the name of the new page.
ga('set', 'page', '/' + aircraft.icao.val);
}
});
}
});
});
}
</script>


I have this in the same html page that i insert with the google code.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest