Jump to content

How to use {expression="\IPS\Member::loggedIn() ?


Recommended Posts

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.

Link to comment
Share on other sites

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
	 */

 

Link to comment
Share on other sites

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()?

 

 

Link to comment
Share on other sites

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 by IPCommerceFan
Link to comment
Share on other sites

@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? 🙂

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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:

image.thumb.png.294582ed4100fad7896f4d9f8a0d4c24.png

Link to comment
Share on other sites

@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. 🙂

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...