PluginProbe
Property Hive / 2.2.3
Property Hive v2.2.3
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / assets / js / frontend / utm-tracker.js

utm-tracker.js in Property Hive 2.2.3, at assets/js/frontend/utm-tracker.js

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(function($)
2 {
3 var qvars = ph_utm_get_url_vars()
4
5 $.each([ 'utm_source','utm_medium','utm_term', 'utm_content', 'utm_campaign', 'gclid', 'fbclid' ], function( i,v ) {
6
7 var cookie_field = ph_utm_get_q_vars(v,qvars)
8
9 if ( cookie_field != '' )
10 ph_utm_set_cookie(v, cookie_field, 30);
11
12 var curval = ph_utm_get_cookie(v)
13
14 if (curval != undefined) {
15 curval = decodeURIComponent(curval).replace(/[%]/g,' ')
16 if (v == 'username') {
17 //Maybe this should apply to all... We'll see...
18 curval = curval.replace(/\+/g, ' ')
19 }
20
21 jQuery('input[name=\"'+v+'\"]').val(curval)
22 jQuery('input#'+v).val(curval)
23 jQuery('input.'+v).val(curval)
24 }
25 });
26 });
27
28 function ph_utm_get_q_vars(v,qvars){
29 if (qvars[v] != undefined) {
30 return qvars[v]
31 }
32 return ''
33 }
34
35 function ph_utm_get_url_vars() {
36 var vars = {};
37 var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
38 vars[key] = value;
39 });
40 return vars;
41 }
42
43 function ph_utm_set_cookie(name, value, days) {
44 if (!value) return;
45 var expires = new Date();
46 expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
47 document.cookie = name + '=' + encodeURIComponent(value) + ';path=/;expires=' + expires.toUTCString();
48 }
49
50 function ph_utm_get_cookie(name) {
51 var escaped = name.replace(/([.*+?^${}()|[\]\\])/g, '\\$1');
52 var pattern = new RegExp('(?:^|; )' + escaped + '=([^;]*)');
53 var matches = document.cookie.match(pattern);
54 return matches ? decodeURIComponent(matches[1]) : undefined;
55 }