Update Profile Field - API or Auto Action

2 years 7 months ago #326012 by marriage_minded_man
Update Profile Field - API or Auto Action was created by marriage_minded_man
I have an independent Javascript media player, that is running inside a Joomla article.

I need that script to continuously update a specific CB user profile field with the progress of that viewer/listener, (e.g. passing a time or numeric value signifying how far ahead they got in the Movie or Album), as the Javascript media player continues to run (so basically periodically or constantly).

The best way I can think of, is to have the Javascript send an API-like call to a specific URL with that value as a parameter in the URL. That way when the user leaves (logs out) and comes back later, I can either use CB Substitutions (or the API again?) to retrieve that value and have them pick up where they left off.

What's the best method to use on the CB side; Auto Actions or API?

With API: I can't find a good use-case example on how to do this (e.g. update user field via API) .

With Auto Actions: I don't see a REST API type trigger that I can use (or even a URL_Visited trigger). And I'm not sure if it will do it silently in the background. I can look at the user clicking a link to save their own progress if need be as a last resort workaround. The Auto Actions method might give me more flexibility with conditioning, so I can say something like "if value being passed is greater than the stored value, then update with the newer/greater value".

What's the best, cleanest, safest, most efficient, least resource intense method to do this?

Thanks.

Please Log in to join the conversation.

2 years 7 months ago #326015 by krileon
Replied by krileon on topic Update Profile Field - API or Auto Action
I don't recommend storing that in a user field. I suggest using browser local storage instead. This would just live entirely in their browser and is called entirely from your JS without hitting your server at all.

developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Alternative is to use a simple browser cookie if you also need this information sent with page headers to the server.


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 to join the conversation.

2 years 7 months ago #326024 by marriage_minded_man
Replied by marriage_minded_man on topic Update Profile Field - API or Auto Action
It’s very long educational media that they are required to watch and are not allowed to skip ahead, so it needs to be stored in their profile since their progress needs to be documented. And if they log in from a different browser they will need to restart the entire media.

The media player already has a progress timestamp, I just need to pass it to their CB user field periodically (either silently in the background or through a user triggered action e.g. a link clicked). Just not sure which method to use in the CB side.

Please Log in to join the conversation.

2 years 7 months ago #326025 by krileon
Replied by krileon on topic Update Profile Field - API or Auto Action

The media player already has a progress timestamp, I just need to pass it to their CB user field periodically (either silently in the background or through a user triggered action e.g. a link clicked). Just not sure which method to use in the CB side.

Ok, then best way to do that is with CB Auto Actions and an HTTP request from JS. The below is example of how to do that.

Global
Triggers: None
Type: Field
User: Self
Access: Registered
Action
Field: YOUR_FIELD_HERE
Operator: Set
Value: [get_timestamp]

Select the field you want to store this to for YOUR_FIELD_HERE. If it's a timestamp then probably a date time field would be best. Now save the auto action and under the global tab you'll have the URL to directly call this auto action. Example as follows.

index.php?option=com_comprofiler&view=pluginclass&plugin=cbautoactions&action=action&actions=ACTION_ID_HERE

Now in your JS you'd call that URL send it with the data timestamp=TIMESTAMP_HERE.


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 to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.221 seconds

Facebook Twitter LinkedIn