Correct API Syntax Java?

I’m a newbie to Hype and Java, but I’m trying to run a short Javascript to trigger a google analytics Event, using the following code on scene load:

gtag('event', 'Load', {

‘event_category’: ‘Scene’,
‘event_label’: hypeDocument.currentSceneName() - hypeDocument.currentLayoutName()
});

… I want the ‘event label’ to be both the Scene Name and the Layout Name. At the moment, I’ve just separated the 2 with a " - ".

Will that work!!!

Thanks in advance,
Adam

Hi Adam!

First off: Java and Javascript are two completely different languages, so I assume you mean javascript. You are certainly not far off in your example! The correctly way of concenating (the fancy term for put together) is:
‘event_label’: hypeDocument.currentSceneName() + hypeDocument.currentLayoutName()

If you want to add something in the middle to separate the two, you just another string like so:
‘event_label’: hypeDocument.currentSceneName() + ' - ' hypeDocument.currentLayoutName()

Welcome to web programming, it is great fun!

Thank you, that’s great!

Just a heads up that sometimes when copying quotes from these forums, you get ‘smart quotes’ instead of regular quotes (which will work in JavaScript).

So those two lines would be:

'event_label': hypeDocument.currentSceneName() + hypeDocument.currentLayoutName()
 

'event_label': hypeDocument.currentSceneName() + ' - ' hypeDocument.currentLayoutName()

The smart quotes were copied from the code you posted @adametheridge18 in your first post. To avoid this, select code and click the code button: 28%20PM

Just want to help yall avoid headaches!

2 Likes