Adding "mobile device status" to an affiliate link variable

Joined
Dec 31, 2016
Messages
238
Likes
132
Degree
1
#1
I'd like to get user device on my website, then append them my affiliate links, which have a variable (like &UID=").

Any tips?

Thinking about using this plugin: https://da.wordpress.org/plugins/wp-mobile-detect/

Which has a function
Code:
wpmd_is_phone()
I could simply call this, but how would you add them to in-post links?

I suppose you could use a Pretty Link type plugin and do some modifications.
 

Ryuzaki

女性以上のお金
Staff member
BuSo Pro
Digital Strategist
Joined
Sep 3, 2014
Messages
2,920
Likes
5,358
Degree
7
#2
This sounds like a job for Javascript or an affiliate link management system, I think. Others might correct me though.

The reason I say Javascript is because your outbound links will be stored in the database within wp-posts. You'll have a real bad time trying to directly evaluate and change those each page load and potentially slow down your site.

With Javascript you could detect the user-agent, and if the user-agent matches a specific list of mobile ones, then attach the right URL parameter after the page load. Same for tablet, laptop, desktop. I'm assuming you're trying to get conversion data. This way you don't have to change the source code.

Alternatively, you could create a PHP redirection system that detects user agent and then maps the click to a specific text file that stores your redirections. Each text file would contain the same set of affiliate link redirections but attach the correct URL parameter variable for the user-agent. This doesn't sound ideal if you're already rocking and rolling but if you set it up from day one it might make more sense.

I'd go for Javascript myself in this case.