I'm trying to create a rule that will flag a user who was referred by an affiliate when she registers and has subscriber role on behalf of the affiliate. The goal of this is to list all users referred by an affiliate and calculate the commission with views.
I tried the rule below but users didn't get flagged. I will appreciate some help. Thanks.
Event:
User has logged in
Condition:
User has cookie with affiliate_nid and campaign is active
Action:
(1) Add a variable:
Parameter: Type: Affiliate campaign
Provides variables: Added variable (variable_affiliate)
(2) Flag a user:
Parameter: Flag: Affiliate referred user, user: [account], User on whose behalf to flag: [variable-affiliate:affiliate], Permission check: false
Comment | File | Size | Author |
---|---|---|---|
#10 | affiliate_ng-affiliate_relationship-1869620-10.patch | 9.86 KB | Perignon |
#7 | affiliate_ng-affiliate_relationship-1869620-7.patch | 9.85 KB | deggertsen |
Comments
Comment #1
mario_prkos CreditAttribution: mario_prkos commentedI needed something similar. I used user reference for marking referral. I also, did some small amount of coding. I built action that perform saving user references to user profile.
In file my_module.rules.inc
Then I created rules:
event: user logged in
condition: Check cookie: affiliate_uid = [site:current-user:uid]
condition: User has cookie with affiliate_nid and campaign is active.
event: save referral
I created entity reference field in user profile that points to his referral .
Using Order views and relationship to referral field you can list who buy what and to whom is users related as referral.
Comment #1.0
mario_prkos CreditAttribution: mario_prkos commentedformatted
Comment #2
Perignon CreditAttribution: Perignon commentedThis to me seems very valuable. I am just trying to think where it should go/reside. I also maintain the module Commerce Rules Extra. Maybe this could have a home there or as a submodule under Affiliate NG. There would need to be some controls over the field attached to the user entity though the UI. But the above code can be used for anyone that would need this functionality immediately. The primary focus for Affiliate NG right now is getting some usable reports of the data being recorded.
Comment #3
deggertsen CreditAttribution: deggertsen commentedI will probably be needing this functionality as well. Concerning where the extra functionality should be added, I personally think it should be a submodule under Affiliate NG called something like "Affiliate User Relationship" or "Affiliate User Link". This is what I see the module needing to do:
I wonder if the title of this issue should be renamed to something like "Permanently link users referred by affiliates".
Comment #4
deggertsen CreditAttribution: deggertsen as a volunteer commentedI did it. Here's a patch with the new module "Affiliate Relationship". Check it out and give me your feedback.
Thanks to mario_prkos for his code in #1.
Comment #5
deggertsen CreditAttribution: deggertsen as a volunteer commentedAnyone else willing to look at this?
Comment #6
deggertsen CreditAttribution: deggertsen as a volunteer commentedI found a few problems with my last patch and have fixed them with this one. I'm now using this on a production site.
Comment #7
deggertsen CreditAttribution: deggertsen as a volunteer commentedOops. Forgot to define the new rule parameter in the default rule. Hopefully that will be it!
Comment #8
george2u CreditAttribution: george2u commentedHi deggertsen , thanks for creating this, it seems to be something I am after too.
However when I tried to get the 'relationship' module, the module page says it is abandoned and suggested to use 'relation' module instead?
Comment #9
deggertsen CreditAttribution: deggertsen as a volunteer commented@george2u, I'm not sure what 'relationship' module you are referring to (link would help), but I'm talking about the one that should be created with the patch in #7 called "affiliate_ng_relationship" that is part of this same affiliate-ng module project. I'm not talking about the 'Relationship' module if that's what you are talking about as indeed that module is no longer supported.
Does that make sense?
Comment #10
Perignon CreditAttribution: Perignon commentedMinor change. Use a different tag in the view other than "default". I have a ton of views, have to use tags :-D
Comment #11
Perignon CreditAttribution: Perignon commentedI been working with this tonight and I see one very big hole in this module. This saves affiliate information only if the user has logged in and editing their account.
Let's back up and track the user registration. You are missing a valuable step in a digital funnel, tracking user registration on your site. What if someone does not get the activation email? You have missed a valuable piece of data to react to in your business logic. I want to reach out to accounts that have registered from an affiliate and see if there was some problem.
Comment #12
deggertsen CreditAttribution: deggertsen as a volunteer commented@Perignon, would we add another action to be triggered on creation of a new user account? What would you suggest? I agree with your point that it is missing an important part. For my use case I actually only need it for login, but I think having an action at registration would be good.
Comment #13
Perignon CreditAttribution: Perignon commentedI actually got it to work. Forgot to come back and post here. If you add the action "After saving a new user account" to the Events portion it works for both!
Comment #14
deggertsen CreditAttribution: deggertsen as a volunteer commentedLovely! I thought that might be the case. Would you say this is ready to commit?
Comment #15
Perignon CreditAttribution: Perignon commentedYeah put it in dev. It's a small submodule. I am looking at making another submodule that does the same thing to an order object.
Comment #17
deggertsen CreditAttribution: deggertsen as a volunteer commentedWe should probably create some documentation for this sub-module somewhere, but I've committed it anyways. I'll open a new issue concerning documentation.