Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Module to show on the second page of our site

Module to show on the second page of our site

Hello!

I am trying something very simple (having in mind the metamod pro capabilities), but i can not manage to make it myself. Please help me!

What i want to do with an example so that i can be clear.

Someone comes to a page of my site from google or facebook or any referer that links to any random page of my site.

We need a metamod module that hides module (id 261) on that (landing) page.

So this page loads and no module (id 261) is shown.

So far so good!

Then the user clicks somewhere to go to another page of the site.

When the second page of our site loads, we need to show module (id 261) that did not show on the previous (landing) page. So the visitor has seen module (id 261).

Then set a cookie that does not allow the module (id 261) to show again for 24 hours.

After 24 hours the cookie is deleted and everything can start over.

Thank you in advance!

liaskas
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Module to show on the second page of our site

Hi liaskas,

This is a very interesting scenario. MetaMod can certainly do this!

Let's list the requirements so I know what we're aiming for:

1 - when someone lands on the site from ANY referrer other than "from the same web site", hide the module. I assume this includes people hitting the front page (or any page) of the site for the 1st time, or from a bookmark, or from typing in the URL themselves?
2 - the user navigates to some other page on the same site (referrer is now from the same site) - show the module this time
3 - but set a cookie so after any subsequent page views (referrer from same site OR from any other site) the module is hidden.

We'll use the cookie to indicate 2 things:
a - set to "shownext" on the 1st page view, so that the 2nd page view will show the module
b - when the module is shown, set the cookie to the current timestamp so that in 24 hours it can be deleted and the module shown again.

Another way of putting this would be, when a page is viewed:

1 - Does the cookie equal "shownext"?
YES: set the cookie to the current timestamp, show the module. It doesn't matter what the referrer is.
NO: continue...

2 - Is there a valid timestamp cookie (24 hours old or less)?
YES: Don't display the module. It doesn't matter what the referrer is.
NO: continue...

3 - Is there a non-internal referrer?
YES: we must be on the 1st page. Hide the module and set the cookie to "shownext".
NO: we must be in the middle of a session with an expired cookie. Show the module and set the cookie to the current timestamp.

I'm fairly confident this logic does what you are asking for. The only "gotcha" is if the user is growing your site "almost" 24 hours after their 1st visit. When 24 hours is up, they are still browsing your site (internal referrer). At this point "3:NO" happens. I'm assuming that you want the module to show once at that point and the timer reset?

Ok so here's the PHP code:

$mysite = 'http://www.mysite.com/'; // customise this!
$cookiename = 'welcome';
$mod_to_display = 261;
$now = time();
$week = $now + 60*60*24*7;
$c = JRequest::getVar($cookiename, '', 'cookie');

// Part 1: deal with "shownext"
if ($c == 'shownext') {
  // set the timestamp. Allow it for a week in case of client with bad clock or timezone
  setcookie( $cookiename, $now, $week, '/' );
  // display the module and stop.
  return $mod_to_display;
}

// Part 2: deal with valid timestamp
$c = (int)$c; // convert to integer
$timedifference = time() - $c; // in seconds
// is time difference less than 24 hours?
if ($timedifference > 0 and $timedifference < 24*60*60) {
  // it's less than 24 hours - don't display module. Just stop.
  return;
}

// Part 3: It's not "shownext" and no valid timestamp.
// Must be 1st visit overall, or the timestamp was over 24 hours.
if (! $core_genius->check('referrer starts with ', $mysite)) {
  setcookie( $cookiename, 'shownext', $week, '/' );
  return;
}
// We must be in the middle of a session with an expired cookie.
// Show the module and set the cookie to the current timestamp.
setcookie( $cookiename, $now, $week, '/' );
return $mod_to_display;


I've done some basic testing on this and it seems to do the right thing smile
Please let me know how you go with it.
Last thing to note: you need to customise the "$mysite" variable to your site base URL. It uses that to determine whether someone was connecting with a referrer "on-site" or from off-site. Note that you should restrict your site to use either the www or non-www variant of the domain name, and put a rule into the .htaccess file to enforce this. Otherwise, this PHP code won't work properly for people using the "wrong" version of the domain.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3319 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1675
Total Polls:
6
Total Posts:
5917
Posts this week:
6
User Info:
 
Total Users:
11571
Newest User:
craig6111
Members Online:
2
Guests Online:
234


Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked