Universal Auto Action to store user location

5 years 10 months ago #305344 by MarlonFungai
Universal Auto Action to store user location was created by MarlonFungai
I want to create an auto action that saves the uri that the user is on, on every page for all registered users. I have tried various combinations and I can't get it to work.

I have created a code auto action triggered by the joomla_onContentPrepare action that keeps the required code and places it in a variable cb_sitelocation as follows:

$user->set( 'cb_sitelocation', "" );

$pageURL = (isset( $_SERVER ) && $_SERVER == 'on') ? "https://" : "http://";
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
$trim_query_string = false;
if( ! $trim_query_string ) {
$user->set( 'cb_sitelocation', "$pageURL" );

} else {
$url = explode( '?', $pageURL );
$user->set( 'cb_sitelocation', "$url[0]" );

}

I have a CB content module that displays the username on every page to initialize CB and I can see the action executes but the data is either never stored or my data is stored not the users.

Please Log in to join the conversation.

5 years 10 months ago #305352 by krileon
Replied by krileon on topic Universal Auto Action to store user location
CB Auto Actions can't act on Joomla events unless you've CB Auto Actions Bot installed and published. With that said content prepare could easily fire 20+ times on a single page and do not recommend using that event. Additionally you are never calling a ->store in your code so it's not going to save anything to begin with. You may also need to set User to Self since that event doesn't have a user object. As for what Joomla event to use you'll probably need to use something early in the rendering process like joomla_onAfterRespond as that fires after the renderer and router and should only do so once.


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.
The following user(s) said Thank You: mikerotec

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.361 seconds

Facebook Twitter LinkedIn