Skip to content

Instantly share code, notes, and snippets.

@raininglemons
Last active November 28, 2017 14:35
Show Gist options
  • Save raininglemons/720f3fe2896df62e4669b721736fa104 to your computer and use it in GitHub Desktop.
Save raininglemons/720f3fe2896df62e4669b721736fa104 to your computer and use it in GitHub Desktop.
seo script example (as used on foxy)
// @flow
import store from '../store';
import getCookie from './Cookie/get';
export default () => {
const { isLoggedIn, profile } = store.get('player').getState();
if (isLoggedIn) {
if (!profile || (!profile.id && !profile.tag)) {
return null;
}
if (profile.tag) {
return profile.tag;
}
return profile.id;
}
const cookieValue = getCookie('AffiliateID');
if (cookieValue) {
return cookieValue;
}
const seoValue = getCookie('AffiliateID2');
if (seoValue) {
return seoValue;
}
return null;
}
(function(require) {
/**
*
* So since the whole SEO affiliate setup has become somewhat convoluted, we'll run with this behaviour:
* We'll store 2 AffiliateIds.
*
* AffiliateId1
* - conventional affiliate id.
* - populated from ?a=
* - lasts 30 days
* - is overridden by subsequent affiliate ids. (Spoke a while back to Active Wins and this is their normal and preferred behaviour)
*
* AffiliateId2
* - assigned based on referrer (essentially an SEO affiliate id)
* - persists for the users session (so until they close the browser)
*
* When passing the user to either the mobile app or the reg form we will send them with affiliate id 1 if it exists, then if not we'll pass it with affiliate id 2.
*
*/
var setCookie = require('app/utils/Cookie/set')['default'];
var affiliateId = null;
var referrer = self.document.referrer;
try {
referrer = self.parent && self.parent.document && self.parent.document.referrer
|| self.document.referrer;
} catch (e) { }
/**
Rules
**/
if (referrer.match(/google\./)) {
affiliateId = '2748.26';
}
if (referrer.match(/altavista\.|aol\.|ask\.|bing\.com|msn\.|search\.|yahoo\.|yandex\.ru/)) {
affiliateId = 2748.25;
}
/**
End of Rules
**/
if (!affiliateId) {
return;
}
setCookie('AffiliateID2', affiliateId, 'session', '/');
})(require);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment