Google Analytics Custom Variable

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
4/16/2013 5:56:43 PM
Gravatar
Total Posts 5

Google Analytics Custom Variable

Using 2.3.8.3 MSSQL

Hey everyone; we are in need of updating a mojo portal site that was setup by a developer long ago that is no longer here and didn't document any of his work... I just have one task and that is to add a custom variable to google analytics for the site to regsiter with google the email of the user that is logged in and visiting pages.

I normally do this via Javascript code in a non-Mojo portal environment.

Could someone help me with following questions?

  • I see the GoogleAnalyticsScript.cs  in the SMHT\mojoPortal.Web.Controls\google\Analytics folder.. and it is intuitive enough how I could update that code to add what i need, but it seems our mojo portal published version does not include this file on our live server... so how does one go about this in code?
  • Is it possible to do this via the Gui Admin?

any help appreciated in advance

Thanks

 

4/17/2013 11:46:02 AM
Gravatar
Total Posts 18439

Re: Google Analytics Custom Variable

Hi,

I would think you could use javascript to set custom analytics variables in mojoPortal just as in other environments, however storing email address or anything that personally identifies a user is against the terms of service for google analytics. Even storing a user id that ties the user back to your own data is against the rules as far as I understand it.

Example of javascript to set a custom variable

<script type="text/javascript"> 
_gaq.push(['_setCustomVar', 1, 'member-type', 'customer', 1]);
 </script>

Hope that helps,

Joe

4/17/2013 12:02:55 PM
Gravatar
Total Posts 5

Re: Google Analytics Custom Variable

Joe; thanks so much for the help...can I just ask you as far as your JS solution, if I add the JS I need (and I know the script you are talking about, usually like I said that's how I do it in non mojo world).... can you answer

  1. Will that not interrupt however the mojo portal is doing analytics currently (that .cs file I mentioned)? We DO Have data from google via mojo portal (standard out of the box page tracking) ... so something is calling google... but how do you tell what that is with the deployed mojoportal.web version (mojoportal.web is all that was published by developer)
  2. If I decide to do it via JS.. WHERE is best to put it? what page in mojo (default.aspx good enough?)

 

thanks so much.

 

4/17/2013 12:59:37 PM
Gravatar
Total Posts 18439

Re: Google Analytics Custom Variable

First you should not modify any mojoPortal source code, so don't think in terms of changing things in .cs files.

The way the google analytics scripts work is that at the top of the page an array is declared and you push any supported google analytics things into the array as in the sample code I posted before. Then at the bottom of the page the google script will process all of the items in that array. So adding a custom script that pushes custom variables into the array should not cause any problem. If you view the source of the rendered page you should be able to see what the google anlytics scripts are doing.

Generally I would put the script in the layout.master file of the skin but below the top google analytics control.

However I don't know how you would get the needed data from there (you could detect the user from server side code but again it is against the rules to push the user email or any other identifier into google analytics), it would be best to implement a custom usercontrol and embed that in layout.master then from code behind you can do any server side logic to determine what your script should do.

Doing these things does require knowledge of asp.net

4/17/2013 2:53:35 PM
Gravatar
Total Posts 5

Re: Google Analytics Custom Variable

Joe thanks;

.NET is actually what I do day to day, so with your help I think I understand the path

  1. insert typical JS code I use in our other applications to send the custom variable of choice to GA in the master layout page on .aspx pages (front end)
  2. I should be able to see results with in a day I would think if it's working on the analytics side data.
  3. don't modify .cs files in Mojo.. got it...

will let you know how it goes

4/17/2013 4:17:27 PM
Gravatar
Total Posts 5

Re: Google Analytics Custom Variable

and to note, you are correct, we are not sending email address, but we want to send login UserId (#). thanks again joe.

 

4/17/2013 4:29:48 PM
Gravatar
Total Posts 18439

Re: Google Analytics Custom Variable

If I thought that were allowed I would already be doing that in mojoPortal but I'm pretty sure that is against the terms of service for google analytics. You are not allowed to use anything to correlate the data to specific users even from your own database. UserId could be used that way and is considered as personally identifying users.

"PRIVACY . You will not (and will not allow any third party to) use the Service to track or collect personally identifiable information of Internet users, nor will You (or will You allow any third party to) associate any data gathered from Your website(s) (or such third parties' website(s)) with any personally identifying information from any source as part of Your use (or such third parties' use) of the Service. You will have and abide by an appropriate privacy policy and will comply with all applicable laws relating to the collection of information from visitors to Your websites. You must post a privacy policy and that policy must provide notice of your use of a cookie that collects anonymous traffic data."

I would recommend against passing userid or any other user specific key as a custom variable in google analytics.

Hope that helps,

Joe

4/17/2013 4:32:41 PM
Gravatar
Total Posts 5

Re: Google Analytics Custom Variable

got it. I just got put on to this project as I stated in the beginning, so.. good to know all this info about google terms.

thanks

You must sign in to post in the forums. This thread is closed to new posts.