Luciano
Luciano

Reputation: 573

Analytics custom vars in a Google Site

Is it possible to register a custom var in a google site? I've been trying for a week and still can't get it.

I know there are two ways to do this.

Can anybody help me? the problem is in google sites only, creating an app script, and adding it as a gadget.

Thanks.

Upvotes: 3

Views: 300

Answers (3)

Brian Cray
Brian Cray

Reputation: 1275

Since Google Sites doesn't allow dynamic insertion, just add the script explicitly:

<script type="text/javascript" src="https://ssl.google-analytics.com/ga.js"></script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_setCustomVar', 4, 'customVar4', "cuatro", 2 ]);
  _gaq.push(['_trackPageview']);

</script>

Upvotes: 1

Polyana Fontes
Polyana Fontes

Reputation: 3216

As described in this help page

  1. Go to the Google Sites page that you’d like to embed HTML in.
  2. Go to the Insert menu and select HTML Box.
  3. In the dialog that opens, add HTML, CSS and/or Javascript code.
  4. Now you can insert your <script> tag

Try to add the common code snippet:

<script type="text/javascript">
_gaq.push(function() {
    var tracker = _gat._getTrackerByName();
    tracker._setCustomVar(1, 'Feedback', 'Closed', 1);
    tracker._trackPageview();
});
</script>

I also recommend you to check the Google Analytic's devguide.

Upvotes: 3

I29
I29

Reputation: 686

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking

Upvotes: 2

Related Questions