Is there a value stored in session by the affiliate program

Is there a value that I can grab from the session when someone uses an affiliate link that associates this person to the affiliate?

  • Paul

    @Hatchman,

    When a public user visits an affiliate link and arrives at your site there is a _COOKIE set. The value of this _COOKIE is the affiliate user_id whose owns the incoming link.

    There is a handy function you can call as part of the Affiliate plugin which will check the current user's COOKIEs for an affiliate hash and return the affiliate user's user_id.

    $affiliate->get_affiliate_user_id_from_hash();

    And obviously if you are using this inside your own template functions you need to call
    global $affiliate;

  • Hatchman

    @Paul

    ok, good to know. This obviously lets me track more things easily. Have you guys work on integration into the event system?

    BTW... the other day in your session when I was talking about performance issues with the server and wordpress. There are obvious issues here that I was wondering if there are articles that help. Most of the conversations are vague and simplistic. The main problems I see is the amount of memory used, the time to process the page, and overall page speed when tested with google tools. Caching obviously helps but what is the best way to set up wordpress for performance? (Links appreciated.)

    Thanks

  • Paul

    ok, good to know. This obviously lets me track more things easily. Have you guys work on integration into the event system?

    I've been working on a rewrite of the Affiliate plugin. Still working on it as I have almost 20 other plugins to support. It will come an I do plan on adding integration with both Events+ and Appointments+. Though it depends on how those other plugins work. The way the Affiliate plugin works with say Membership and MarketPress it is dependent on those other plugins to send the needed messages. So it depends on it the hooks are there in Events and if not how soon the plugin developer can get them added.

    BTW... the other day in your session when I was talking about performance issues with the server and wordpress. There are obvious issues here that I was wondering if there are articles that help.

    Agreed.

    You might want to not focus so much on an external tools but maybe look at some of the performance plugins which can help identify slow queries and memory utilization.

    https://linkonym.appspot.com/?https://github.com/johnbillion/QueryMonitor
    http://wordpress.org/plugins/search.php?q=performance

  • Paul

    @Hatchman,

    I have large affiliate tracking needs than currently available.

    Can you be any more specific? At the moment I agree the tracking is somewhat less than basic. We are trying to push out the rewrite as soon as possible but takes time to write the code. So if you have ideas would love to hear them.

    I was hoping to do some basic tracking by adding the affiliate_user_id field to the db on the tables of the related plugins.

    Like most plugin developers I would prefer you not write directly to the tables unless you full understand the way the fields relate.

    Is there documentation in this regards?

    Not really. Then again you've not asked anything specific so can't really point you to a specific are of documentation.

  • Hatchman

    First, I have been writing php, java and sql code for fifteen years. I am actually a trained db admin so you can see why I have some troubles with wordpress. I have written systems css systems with complex affiliate tracking systems that I am still using. My most recent project have started to use wordpress because everybody wants wordpress. I say this so you consider this differently than you would from the norm of wordpress users.

    Tracking users is normally a simple task of adding a field to the db with the related affiliate id. Wordpress likes to cram everything into one table so it can get a little trickier but most of the time it is still a two field key. I have not explore the code simply because it begins to frustrate me and I want to change it so I build simple handlers to put information in the db that I can process external to wordpress until I actually need to display it for an end user then I go through the trouble of building a GUI.

    So with all that said and wasting more of your time which I do apologize, my question would be what is included in the plugins inside of the affiliate system (membership, listings. etc...)? Are there cross join tables added to the db and then an interface modification to display information for both the end user and the admin? When you were referring to plugins that have hooks so the affiliate system can link in, what is the main purpose of the hooks?

    Thanks Again

  • Paul

    @Hatchman,

    First, I have been writing php, java and sql code for fifteen years. I am actually a trained db admin so you can see why I have some troubles with wordpress.

    Just 15 years? Kids these days. I have almost 8 on top of that. And I was also DBA trained on DB2 and Oracle. I've written in over 20 languages. Mostly C/C++, Java, PHP, RPG, COBOL. Though I shudder when I think about those big iron mainframe days of the late eighties. And I've been doing deep WordPress development since 2005. I do find it best to through all those data normalization concepts out the window when dealing with WordPress or most web based packages. Keeps my sane. Now that we have each others resumes we can get down to business.

    my question would be what is included in the plugins inside of the affiliate system (membership, listings. etc...)?

    By itself Affiliate only captures the initial inbound link tracking. It needs to add-ons for MarketPress, Membership, etc to be 'aware' of how those other systems work. For example when someone places an order via MarketPress the Affiliate plugin received a 'message' from MarketPress. that a transaction has taken place. This is the 'hook'. More on hooks below.

    Are there cross join tables added to the db and then an interface modification to display information for both the end user and the admin?

    Yes and no. There are three tables user by Affiliate to store information about what it tracks. One is a summary table, Another is a details transaction table. And the third is used only to track inbound link counts. I'll let you figure out which is which.

    When you were referring to plugins that have hooks so the affiliate system can link in, what is the main purpose of the hooks?

    A 'hook' in WordPress is a combination of a trigger and a simply function call. This hook can be an action or filter http://codex.wordpress.org/Plugin_API/Hooks. These hooks in WordPress allow other module/plugins to 'subscribe' to functionality within WordPress or even other plugins. So in code when you see a plugin setting up with add_action() or add_filter(). This means it is registering itself with that hook and providing a callback function to be executed when that particular even occurs.

    Actions and Hooks. Oh my -
    An action hook is used to pass some variable to another function where it will trigger some sub-process. A filter on the other hand also passes a variable but it expects some result back. I'll try and give you real world examples of both.

    MarketPress to Affiliate action hook -
    In MarketPress when an order is marked as paid within the system an action hook is executed. This hook is named 'mp_order_paid'.

    if you look into the affiliate plugin folder in affiliateincludes/addons/marketpress.php you will find on line 12

    add_action( 'mp_order_paid', 'affiliate_marketpress_paid_order' );

    This line means affiliate is 'subscribing' to the action hook 'mp_order_paid' and when that action is executed from within MarketPress then the affiliate function 'affiliate_marketpress_paid_order' will be called.

    This lets affiliate act on the action which has occurred within MarketPress within having to write code directly in MarketPress to have it call the Affiliate code.

    So how is the 'action' executed in MarketPress? Simply enough there is a line do_action('mp_order_paid', $order) somewhere in MarketPress within the order processing logic. The $order variable is the order structure being processed. The beauty of this is the Affiliate or external code does not need to be aware of how exactly MP processes the order. Just that it will call that action hook when the order is complete.

  • Hatchman

    You are the man. I figured as much... Your bed side manner led me to believe that you were smart and experienced.

    Why would it not make since to simply put the affiliate id into the plugin table? I guess to answer my own question, you can not rely on other plugins not changing their structure thereby breaking the code.

    If you control all the elements it would seem to make more since to track these items in their own tables with an affiliate id. Having a program send information back to the affiliate tracking system then organizing this data so you can display it in a reliable manner and count on no changes happening to that data (refund, charge back, etc...) seems to be a nightmare.

    Thanks again Paul

  • Paul

    Why would it not make since to simply put the affiliate id into the plugin table? I guess to answer my own question, you can not rely on other plugins not changing their structure thereby breaking the code.

    It is not so much a matter of other plugins changing the structure. Generally plugins will only make changes to their own tables if they use then. I would say 95% of all plugins do not use custom tables but store everything into the default WordPress tables.

    For the storage of the affiliate id, Well. it depends on how you look at the environment as a whole. The affiliate ID is the is what the public sees and it added to the end of the URL like http://www.somesite.com?ref=xxxxx=12345. This affiliate id 'xxxxx=12345' is really just an alias for the WP user ID. Sure it could be stored as part of the affiliate tables to reference the details. But much easier just to store the affiliate id as part of the WP user meta. Then user the user ID as part of the affiliate details. Much like the way WordPress does with Post data. It doesn't store the user login as part of the post table. It stores the user ID as the author of the Post.

    If you control all the elements it would seem to make more since to track these items in their own tables with an affiliate id.

    I'm not sure what elements you are referring to. Add-ons? As for tracking the affiliate plugin does use its own tables. There are three of them.

    Having a program send information back to the affiliate tracking system then organizing this data so you can display it in a reliable manner and count on no changes happening to that data (refund, charge back, etc...) seems to be a nightmare.

    Well yes and no. The Affiliate plugin for example collects and manages and yes displayed the affiliate transactional details. But the beauty of the WordPress action/filter hooks is I don't have to add specific code to say MarketPress to have it write directly to the Affiliate tables. Then some time down the road if the table schema changes for affiliate I don't have to worry about getting MarketPress updated because not all members update to the latest version of our plugins when they are released. To me that would be the nightmare.