Maxxius Posted October 20, 2021 Posted October 20, 2021 Hello, I'm trying my hand at setting up google tag manager and I wish to return as many useful values as possible. I had success with this code to determine member group by putting this {expression="\IPS\Member::loggedIn()->member_group_id"} I tried looking in templates for other things to gather using this way but I was only able to find rank score. That's it. Does anyone know any other values like rank title. Registration date and similar? using {expression="\IPS\Member::loggedIn()->some_value"} I'd take these variables that are returned and put them as variables in the dataLayer part of google tag manager script.
Daniel F Posted October 20, 2021 Posted October 20, 2021 You could either take a look at the core_members database table or the system/Member/Member.php class to see all the available fields.  The lazy way would be probably Member::logged()->apiOutput() , which would return an array with following data: /** * Get output for API * * @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials * @param array|NULL $otherFields Array of additional fields to return (raw values) * @return array * @apiresponse int id ID number * @apiresponse string name Username * @apiresponse string title Member title * @clientapiresponse string timezone Member timezone * @apiresponse string formattedName Username with group formatting * @apiresponse string ipAddress IP address used during registration * @apiresponse \IPS\Member\Group primaryGroup Primary group * @clientapiresponse [\IPS\Member\Group] secondaryGroups Secondary groups * @clientapiresponse string email Email address * @apiresponse datetime joined Registration date * @clientapiresponse string registrationIpAddress IP address when registered * @clientapiresponse int warningPoints Number of active warning points * @apiresponse int reputationPoints Number of reputation points * @apiresponse string photoUrl URL to photo (which will be the site's default if they haven't set one) * @apiresponse bool photoUrlIsDefault Indicates if the value of photoUrl is the site's default * @apiresponse string coverPhotoUrl URL to profile cover photo (will be blank if there isn't one) * @apiresponse string|null profileUrl URL to profile * @clientapiresponse bool validating Whether or not the validating flag is set on the member account * @apiresponse int posts Number of content item submissions member has made * @apiresponse datetime|null lastActivity Last activity date on the site. * @clientapiresponse datetime|null lastVisit Last distinct visit date on the site. * @clientapiresponse datetime|null lastPost Latest content submission date. * @apiresponse int profileViews Number of times member's profile has been viewed * @apiresponse string birthday Member birthday in MM/DD/YYYY format (or MM/DD format if no year has been supplied). * @apiresponse [\IPS\core\ProfileFields\Api\FieldGroup] customFields Custom profile fields. For requests using an OAuth Access Token for a particular member, only fields the authorized user can view will be included * @apiresponse [\IPS\core\Achievements\Rank] rank Rank * @apiresponse int achievements_points Points */  Maxxius and IPCommerceFan 1 1
Maxxius Posted October 20, 2021 Author Posted October 20, 2021 Thanks @Daniel F ! It would be awesome to be able to grab the data by using this api thing - Member::logged()->apiOutput() I tried with no luck to pull something using this Member::logged()->apiOutput(). Could you provide at least one working example of full code pulling any one value from the list you gave using Member::logged()->apiOutput()? Â Â
IPCommerceFan Posted October 20, 2021 Posted October 20, 2021 (edited) This works in a custom Pages PHP block: $output = ''; $apiOutput = \IPS\Member::loggedIn()->apiOutput(); $output .= json_encode($apiOutput); echo $output; ^ this will return all of the possible values. If you wanted just rank title and registration date, you'd do: $output .= $apiOutput['joined']; $output .= $apiOutput['rank']['name']; To discover what your options are for working with the member object directly, you'd do: $output .= json_encode(\IPS\Member::loggedIn()->_data); At which point you'll discover the apiOutput method is a lot more straightforward, since you'd then need to learn all the functions necessary to call up the data that isn't in the member object itself. e.g.: $output .= \IPS\Member::loggedIn()->joined; $output .= \IPS\Member::loggedIn()->rank()->title; Hope that helps! Edited October 20, 2021 by IPCommerceFan
Maxxius Posted October 21, 2021 Author Posted October 21, 2021 @IPCommerceFan thank you for your input. But even what you gave me here - these lines of code were not enough to grasp how this works. First off I'm trying to put and access those values in every page of IPS. Not only in pages made by Pages app. I want to put it in GlobalTemplate to be exact since I want to make it work with google tag manager. These variables should return the values of a visitor browsing the website and helping tag manager gather the exact information about a visitor. Could you elaborate more in more basic fashion? 🙂
IPCommerceFan Posted October 21, 2021 Posted October 21, 2021 Hey @Maxxius, yeah, using a Pages block is just my way of quickly testing something out. If we're talkin' page templates, then one thing to remember is anything encapsulated by double curly braces is parsed as PHP, and anything in single curly braces echoes the variable. So, in a template, this would look like: {{$apiOutput = \IPS\Member::loggedIn()->apiOutput();}} {$apiOutput['joined']} {$apiOutput['rank']['name']} You could not, however, do: {\IPS\Member::loggedIn()->apiOutput()['joined']} since there is not a variable in the single curly braces. Where in globalTemplate do you want this to appear, exactly? Maxxius 1
Maxxius Posted October 22, 2021 Author Posted October 22, 2021 Hey thanks! I seem to be getting some results now. Though not all of them. For testing purposes I just paste the code to show near the logo. After I find code to be working I paste it in head. The code is not visible on the site. The variables are wrapped in <script> and get collected by google tag manager. What worked is quite a number of member object values mentioned in here https://invisioncommunity.com/developers/rest-api?endpoint=core/members/GETindex#object-rank HOWEVER outputting RANK did not work with the example you provided: IPCommerceFan 1
Nathan Explosion Posted October 22, 2021 Posted October 22, 2021 (edited) Works fine here: But it also doesn't (and there is a good reason as to why, in my case): Â Question: what version of IPS 4 are you working on? Edited October 22, 2021 by Nathan Explosion Maxxius and IPCommerceFan 2
Maxxius Posted October 22, 2021 Author Posted October 22, 2021 I just realized it does not work on 4.5. Only on 4.6. Thanks for your help guys! IPCommerceFan 1
Maxxius Posted October 26, 2021 Author Posted October 26, 2021 @IPCommerceFan @Nathan Explosion hey guys I got one more question to ask. Can you name an IF clause or something similar so for example: if member then Hello, {expression="\IPS\Member::loggedIn()->member_group_id"}, you have been a member since {expression="\IPS\Member::loggedIn()->member_group_id"}. else Hello. end I want to have additional text around those member values. But only if a member is viewing the page. When a guest visits the page values are missing and what I'm left with is Hello, , you have been a member since I wish it would not be shown at all. 🙂
Sonya* Posted October 26, 2021 Posted October 26, 2021 Look here for member https://invisioncommunity.com/4guides/themes-and-customizations/template-syntax/using-expressions-in-logic-r139/ member translates to \IPS\Member::loggedIn(). {{if member.member_id}}  IPCommerceFan, Daniel F and Maxxius 2 1
Maxxius Posted October 28, 2021 Author Posted October 28, 2021 Thanks! I think I got it. I had fun adding stuff from users and I reached the point where I'd like to display some other things like statistics from the board (total members, total number of posts, blogs etc.). I mean can anyone point me what I'm missing when I place {number="$stats['total_topics']" format="short"} in files I've found this $stats['total_posts'] = \IPS\Db::i()->select( "COUNT(*)", 'forums_posts', array( 'queued = ?', 0 ) )->first(); and I get nothing. I checked out forumStatistics widget code and it has nothing else to it. I bet I'm missing something..
Nathan Explosion Posted October 28, 2021 Posted October 28, 2021 11 minutes ago, Maxxius said: I mean can anyone point me what I'm missing when I place Place it where? Does $stats exist where you've placed it. Show more detail about what you are doing.
Maxxius Posted October 28, 2021 Author Posted October 28, 2021 I'm simply placing it inside a custom Page made by Pages app. I doubt $stats is there 😄
Recommended Posts