Last active
November 28, 2017 14:35
-
-
Save raininglemons/720f3fe2896df62e4669b721736fa104 to your computer and use it in GitHub Desktop.
seo script example (as used on foxy)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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