Last active
December 2, 2019 10:41
-
-
Save konosp/f3899cc074b8c94813f9418d5b0b6c67 to your computer and use it in GitHub Desktop.
Identify the marketing channel based referring domain information
This file contains hidden or 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
| // channel_domain_mapping | |
| var DOMAINS_NATURAL_SEARCH = ['www.google.', 'bing.', | |
| 'search.yahoo.', '.yandex.']; | |
| var DOMAINS_NATURAL_SOCIAL = ['facebook.com', 't.co', 'pinterest.', 'linkedin.com', | |
| 'plus.google','instagram.com']; | |
| var DOMAINS_REFERRING = ['.paypal.com','www.my-bank.com']; | |
| // Returns an array with the channel_id and the referring domain | |
| function identifyChannel( channel_id , channel_domain_mapping , referrer) { | |
| if (referrer && referrer !== '') { | |
| // Extract the hostname portion of the referring URL. | |
| var ref_domain = get_domain_from_url(referrer); | |
| var curr_domain = window.location.hostname; | |
| if (channel_id === REFERRING_DOMAIN) { | |
| // Referring Domains check: confirm that the referring domain | |
| // is present, different than the current domain and | |
| // does not match any domain present in the mapping | |
| if (curr_domain !== ref_domain) { | |
| var res = channel_domain_mapping.every( | |
| x = > ref_domain.indexOf(x) === -1 | |
| ); | |
| if (res) | |
| return [channel_id, ref_domain] | |
| } | |
| } else { | |
| // Referring Domains check: confirm that the referring domain | |
| // matches at least one domain present in the mapping | |
| var res = channel_domain_mapping.some( | |
| x = > (ref_domain.indexOf(x) > -1) | |
| ); | |
| if (res) | |
| return [channel_id, ref_domain] | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment