Panels + User referral isn't working

eranglr - December 3, 2008 - 11:16
Project:User Referral
Version:6.x-1.x-dev
Component:Code: referral
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi there,
I set up the following:

I made a new panel and set it path to user/% (so, it will appear on user profile page).
When testing it with user referral, I saw that either the cookie is not being implented or something else I can't explain.

The referral is not counted using when using panels.

Thanks

#1

kbahey - December 3, 2008 - 16:17

That is an interesting case.

I am hoping that with panels, the original path is still called, but can't be sure with such overriding.

Can you go into the referral.module code and add a print statement where it sets the cookie, and see if it is indeed called? Do that in the beginning of referral_user() too.

If all that fails, then ask in Panels queue if you override /user/uid, what will happen?

#2

asak - February 8, 2009 - 12:14
Component:Code» Code: referral

Hi there i'm jumping in for i need something which seems very close to this use case.

I understand one of the latest commits included the ability to track visits to the user profile as a "referral link", which is great. one of the threads here (http://drupal.org/node/347207) mentioned this doesn't work however when using pathauto.module. Now this issue is about sing panels to override user/uid to a panel page.

From what i understand, both pathauto and panels leave the original path and are only aliases (i think!!).

I'm going to give this thing a spin and see what happens.. this is a great module... i'll post back ;)

#3

asak - February 10, 2009 - 15:41

Ok so the pathauto part is working great. the panels part isn't.

I'm trying to add a print to the referral_set_cookie and referral_user functions, but i keep getting "Array" printed (while not using panels) instead of the cookie info which is what i believe we're looking for - what would be the correct syntex to print that array ($cookie if i understand what's going on...)?

I do however notice that i don't even get the "Array" printed when overriding user/% using panels if that means much...

Thanks!

#4

asak - February 11, 2009 - 14:03

This is something...

I'm trying to use the user visits module (http://drupal.org/project/user_visits) to track visits of the profile page. my problem is the same as with this referral module - no tracking is being done when users visit a panels overridden profile page.

I found a thread in there with a solution, for user visits, and maybe the solution offered there could be used for referral as well. i noticed the patch which was submitted in order to capture visits to user/xx pages (using custom paths) was changed and the code isn't as the code in the patch was. since i don't really understand how both codes work when visiting a profile page, there isn't much i can do here.

The patch for user visit is at http://drupal.org/node/280659 . and alternative solution may be to use Content Profile module and/or APK to make it a bit easier (though i don't know really how/why).

I see that referral module is just using the arg(1) of the path to set the cookie. i don't understand the following code that well, but it seems like it could be the solution (taken from the patch above, while user_visits_path could be set to "user/%" for a panel if i'm not mistaken):

+  // Record visits on custom paths
+  else {
+    $path = variable_get('user_visits_path', '');
+    if (strlen($path) && arg(0)) {
+      $chunks = explode('/', $path);
+      foreach ($chunks as $chunk) {
+        if (arg($i) == $chunk OR $chunk == '%') {
+          if (is_numeric(arg($i)) AND !arg($i+1)) {
+            //Don't count self-clicks
+            if ($user->uid != arg($i)) {
               //Count view
               user_visits_count($user->uid, $node->uid);
+              user_visits_count($user->uid, arg($i));

#5

asak - February 18, 2009 - 08:27

OK i really need to get this done so i gave it some more thought...

Basically - the problem is that referral_user isn't being called when viewing a panel page, since drupal doesn't consider that to be a user page and so hook_user can't work.

I think a possible solution could be to call referral_set_cookie() using some code in a block which will be displayed in the panel, and manually set arg(1) to the uid of the author of the content_profile being viewed. some code would need to be used so that the referral module performs the validations from referral_user(), but besides that I think this should work...

Would best practice be to add another function? it seems there is no way to use the referral_user() function in this case...

I'll try and report back with the results ;)

#6

asak - February 22, 2009 - 21:57

It was simple...

Just needed to create a custom block which a) checks the arg()'s to make sure it's a user node, b) make sure user is anonymous, and c) calls sets the cookie.

<?php
global $user;
if (
arg(0) == 'user' && is_numeric(arg(1)) && $user->uid == 0) {
   
$ur = arg(1);
       
referral_set_cookie($ur);
}
?>

This needs some fixup... but it works!

#7

nikmahajan - August 31, 2009 - 03:26

this doesn't works. I put the code in the block and it got displayed as output.

 
 

Drupal is a registered trademark of Dries Buytaert.