1

I included Google Analytics (javascript) in my Outsystems website via de eSpace Javascript. Now I want to place the Analytics Key in my Site Properties so I can update it easily for every environment.

How can I use a Site Property in my Javascript?

Jeroen
  • 307
  • 1
  • 6
  • 17

3 Answers3

3

You can create a site property to store the Tracking ID.

site Property screenshot

Second, you need to create a webblock with an unescaped expression, and add your javascript this way:

weblock expression screenshot

Finally, you just need to drag you weblock to each webpage you want to track.

cheers, Vera

Vera Tiago
  • 51
  • 2
  • Thanks for your answer, but I want to avoid using a webblock. I want to use the eSpace javascript, so I don't have to add this to every page I made. – Jeroen Apr 04 '16 at 14:43
  • So I think you should set this on the script of the theme. – Bruno Gomes Apr 21 '16 at 11:10
1

I can understand your use case. If I read it correctly, you're trying to use some JavaScript in one espace, that would be run in every page load, something like an

onLoad(function(){
 // your Google Analytics code, but using the value from the site property
})

And in this way, you would be able to update the site property without the need to republish all consumers. Seems like a nice approach :)

On way to be able to achieve this, would be to have your JavaScript to request the key on the fly to the server side, and maybe cache it.

This can be easier or harder depending on the Platform version you're running... But here's a simple way to achieve it.

Add the site property to the espace. Build a page that has no layout, and in the preparation, add a download widget that only downloads the value of your site property. In the same espace, in the espace JavaScript, add an AJAX request to the page I was referring to before, and when you get the response back, start your Google Analytics code.

To be able to use this in every other espace, and in every page, you still need to reference something from the Google Analytics espace though, so that espace JavaScript is run in every page

Hope it helps :)

Pedro Cardoso
  • 373
  • 3
  • 7
1

As far as I know, you cannot use Site Properties in the eSpace JavaScript window. For that, you have to use an escaped expression on a web screen or web block to add your JavaScript code along with the use of Site Properties.

Since you want the same script on all the web screens, I suggest that you add this expression in the Footer web block, so that it will be automatically added to all the web screens you create.

  • Indeed you're right, but the request here was to update a site property and skip the need to republish all the factory. – Pedro Cardoso Jun 26 '16 at 21:29
  • Exactly. When you write the JavaScript in an expression, you can directly access and use Site Properties. So the Analytics Key can stay in the Site Properties and will be used in the JavaScript when needed. – Shehan Thamel Jun 28 '16 at 12:09