Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

How to setup Google Analytic variable with Auto-Action ?

  • dotcom22
  • dotcom22
  • OFFLINE
  • Posts: 522
  • Thanks: 14
  • Karma: 4
11 years 2 months ago - 11 years 2 months ago #232501 by dotcom22
hello

I would like track in GA all users according to their own CBsubs plan. For do that, GA allow the use of "custom variable" who must be implemented with javascript such this one:

Code:
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-12345678-1']); _gaq.push(['_setCustomVar', 1, 'UserType', 'PlanGold', 1]); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); (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>

In practice I suppose is necessary to fire this code with "onafterlogin" trigger and Auto-Action "Inline JS Code" and I tried but without success.

I found an alternative solution who consist to create a simple html page "goldplan.htm" with this code:
Code:
<html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://www.site.com/index.php?option=com_comprofiler&Itemid=126" } //--> </script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-12345678-1']); _gaq.push(['_setCustomVar', 1, 'UserType', 'PlanGold', 1]); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); (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> </head> <body onLoad="setTimeout('delayer()', 1000)"> </body> </html>

Then setup an "onafterlogin" Auto-Action redirect (with related condition about desired user plan) to the above html page. Finally the other small "delayer" javascript, redirect user 1 second later for example to his CB profile. Using this method, the GA code is well fired, however it must be possible to fire the code without this external html page.

any clue ?

I use Joomla 3.3.6 - CB 2.0.4 - CBSubs 4 - Several Incubator plugins
Last edit: 11 years 2 months ago by dotcom22.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48466
  • Thanks: 8280
  • Karma: 1443
11 years 2 months ago - 11 years 2 months ago #232524 by krileon
The below should work I believe.

Type: Code
Trigger: onAfterLogin
Access: Everybody
Method: JS (Inline)
Code:
Code:
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-12345678-1']); _gaq.push(['_setCustomVar', 1, 'UserType', 'PlanGold', 1]); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); (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); })();

All it'll do is just add that JS to the header. Shouldn't need some sort of strange redirect page either. Note you do not need to include the script tags with the Inline JS method; they are only needed with the Header method.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 11 years 2 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • dotcom22
  • dotcom22
  • OFFLINE
  • Posts: 522
  • Thanks: 14
  • Karma: 4
11 years 2 months ago #232563 by dotcom22
Yes I made exactly what you suggest but I don't see any data in Google Analytic after this implementation. It seem the script is not well fired.

However I found another method where I placed the code directly in joomla article. In my specific case, each user are redirected afterlogin to different page...and now I'm able to track each user according to his plan/group.

Ideally I would prefer use Auto-Action for do that..Is strange your suggested method don't work.

I use Joomla 3.3.6 - CB 2.0.4 - CBSubs 4 - Several Incubator plugins

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48466
  • Thanks: 8280
  • Karma: 1443
11 years 2 months ago #232620 by krileon
A redirect occurs directly after login. Probably not enough time for the JS added by CB Auto Actions to do anything. Ideally that JS should be on a landing page and not injected during PHP operations. So placing it in an article and having the article as the landing page is best. Alternative is to see if Google has a PHP API or maybe a REST API that you can use during login.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum