You are not logged in.

andrew22222

Intermediate

  • "andrew22222" started this thread

Posts: 341

Location: Australia

  • Send private message

1

Friday, January 5th 2018, 11:53pm

Display Scene and title in Google Analytics

Hi,

I use this piece of code in my index.html (previously made available here on the forum)

Source code

1
2
3
4
5
6
7
8
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-000000000-1', 'auto');
  ga('send', 'pageview');
</script>


and add this to my xml file

Source code

1
<events onxmlcomplete=" js(ga('send','pageview', get(xml.scene) ) );" />


On Google Real-Time the Active page is
/scene_005

As I've got several individual tours to track which are all in a folder called VT (then in their own folder titled 004, 005, 006, 007 etc.) I'd like to display the title and then the scene.

I changed it to
<events onxmlcomplete=" js(ga('send','pageview', get(xml.title.scene) ) );" />

then on Google Real-Time the Active page is this below but no scene.
/vt/004/


Tried get(xml.scene.title) but still get
/vt/004/


I think I'm missing something really simple here so was hoping anyone could point me in the right direction please?

Also is there a way to track hotspot clicks also that are inside the scene as each one generally has 4-5 hotspots.......... or am I pushing it *smile*


Thanks for your time,

Andrew

2

Saturday, January 6th 2018, 10:10am

untested, but maybe try with get(scene[get(xml.scene)].name);

and you should use a name for your event, i think:
<events name="google_watches" onxmlcomplete="js(ga('send', 'pageview', calc('SCENE=' + scene[get(xml.scene)].name)));" />

for hotspots you can add (or add to) an existing onclick event, of course
txtadd(hotspot[myhotspot].onclick, "js(ga('send', 'pageview', calc('HOTSPOT=' + name)));");

the latter i would implement as an action which is called by each scenes onxmlcomplete event
in the action you must loop through the scenes hotspots and add the onclick event to each of them

This post has been edited 1 times, last edit by "indexofrefraction" (Jan 6th 2018, 10:22am)


andrew22222

Intermediate

  • "andrew22222" started this thread

Posts: 341

Location: Australia

  • Send private message

3

Sunday, January 7th 2018, 12:32am

Thanks for the reply and code Index. Appreciate it.

I tried but no luck. As soon as I mess with it the result defaults to /vt/004/ and nothing afterfor any scenes viewed. I tried it with the event having a name and without.


One solution I did work out yesterday was to add the tour number to the scene name(via find and replace in Notepad ++) so it would look like this

<scene name="scene_004_035"

then when you view Google Real-Time you see this

Active Page
1./scene_004_035



That would at least narrow it down to the 004 tour but it's still hard to identify what 035 is showing as it's just a number. That info is in the title of the scene which is what I'm trying to display at the end

title="B52 Cockpit pilot seat"



I tried the hotspot code to an existing onclick event but get the old xml parsing failed! error message

Element type "hotspot" must be followed by either attribute specifications, ">" or "/>".

Source code

1
<hotspot name="h1" title="" style="info_hotspot"  zoom="false" ath="12.133" atv="8.031" onclick="Galereya(Set_004_005_1); txtadd(hotspot[myhotspot].onclick, "js(ga('send', 'pageview', calc('HOTSPOT=' + name)));"); " />



I'll keep plugging away


Cheers,

Andrew

4

Sunday, January 7th 2018, 9:51am

instead of events onxmlcomplete maybe try to use your scene onstart event
<scene name="scene_004_035" ... onstart="js(ga('send', 'pageview', calc('SCENE=' + scene[get(xml.scene)].name)));" >
...
</scene>

in your hotspots you already have an onclick event, so you dont need to txtadd.
<hotspot ... onclick="Galereya(Set_004_005_1); js(ga('send', 'pageview', calc('HOTSPOT=' + name)));" />

note: in properties (onstart, onclick, etc) you cannot use " again
onclick="debug('hello')" works, but onclick="debug("hello")" does not!

maybe you should post a link to your tour, that would help
best index

5

Friday, January 12th 2018, 6:45pm

Hi,

Quoted

I tried the hotspot code to an existing onclick event but get the old xml parsing failed! error message
Element type "hotspot" must be followed by either attribute specifications, ">" or "/>".

Better put your onclick code into a separate <action> - this way you more possibilities when using several double characters in a string.

Best regards,
Klaus

herrpedro

Trainee

Posts: 140

Location: Lisbon

Occupation: Programmer/analyst

  • Send private message

6

Friday, September 28th 2018, 10:42pm

this was one of the things i wanted to do for a long time

google tag changed it a bit

https://developers.google.com/analytics/…on/gtagjs/pages


now it is enough to

gtag('config', 'property-id', {
'page_title' : 'your title',
});