PageSourceSearch

https://fpt.vn/shop/js/ATTracking.js

js fpt.vn collected 2026-09-24 09:40:14 UTC 7,964 bytes, 196 lines download raw bytes

1//---------------- Note: Patch 23/12/2025
2// Tránh utm khác (fb/google) ghi đè hoặc xoá cookie affiliate đang tồn tại:
3//
4//   aff_sid    | utm_source       | _aff_network   | _aff_sid
5//   -----------|------------------|----------------|----------
6//   không có   | accesstrade      | ✓ lưu          | ✗ không lưu
7//   không có   | facebook/...     | ✗ bỏ qua       | ✗ bỏ qua   (patch: giữ nguyên cookie cũ)
8//   có         | facebook/...     | ✗ xoá cookie   | ✗ xoá cookie (last-click win)
9//   không có   | (không có)       | ✗ không làm gì | ✗ không làm gì
10
11
12//---------------- Note: Trước 30/03/2026
13// Logic track() - Chỉ lưu cookie affiliate khi utm_source === "accesstrade":
14//
15//   aff_sid    | utm_source       | _aff_network        | _aff_sid
16//   -----------|------------------|---------------------|----------
17//   có         | accesstrade      | ✓ lưu "accesstrade" | ✓ lưu
18//   không có   | accesstrade      | ✓ lưu "accesstrade" | ✗ không lưu
19//   có         | facebook/...     | ✗ xoá cookie        | ✗ xoá cookie
20//   không có   | facebook/...     | ✗ bỏ qua            | ✗ bỏ qua
21//   bất kỳ     | (không có)       | ✗ không làm gì      | ✗ không làm gì
22
23
24//---------------- Note: Từ 30/03/2026
25// Logic track() - Lưu aff_sid bất kể utm_source là gì (hoặc không có source):
26// _aff_network luôn đồng bộ với _aff_sid hiện tại (clear nếu không có source mới):
27//
28//   aff_sid    | utm_source    | _aff_network        | _aff_sid
29//   -----------|---------------|---------------------|----------
30//   có         | accesstrade   | ✓ lưu "accesstrade" | ✓ lưu
31//   có         | facebook/...  | ✓ lưu "facebook/..."| ✓ lưu
32//   có         | (không có)    | ✗ xoá cookie        | ✓ lưu
33//   không có   | bất kỳ        | ✗ không làm gì      | ✗ không làm gì
34
35var AT = {
36    cookie_duration: 30,
37    aff_utm_source: "accesstrade",
38    aff_utm_sources: ["accesstrade"],
39    aff_source_param: "utm_source",
40    aff_sid_param: "aff_sid",
41    is_reoccur: 1,
42    is_lastclick: 1,
43    campaign_id: 0,
44    result_id: 30,
45    cookie_domain: null,
46    init: function(a) {
47        this.cookie_duration = a.cookie_duration ? a.cookie_duration : 30;
48        this.aff_utm_source = a.aff_utm_source ? a.aff_utm_source : "accesstrade";
49        this.aff_utm_sources = a.aff_utm_sources ? a.aff_utm_sources : ["accesstrade"];
50        this.aff_source_param = a.aff_source_param ? a.aff_source_param : "utm_source";
51        this.aff_sid_param = a.aff_sid_param ? a.aff_sid_param : "aff_sid";
52        this.is_reoccur = a.is_reoccur == 0 ? 0 : 1;
53        this.is_lastclick = a.is_lastclick == 0 ? 0 : 1;
54        this.campaign_id = a.campaign_id ? a.campaign_id : 0;
55        this.result_id = a.result_id ? a.result_id : 30;
56        this.cookie_domain = a.cookie_domain || null
57    },
58    check_scope: function() {
59        var a = this.get_cookie("_aff_network") || this.get_param(this.aff_source_param);
60        if (a == this.aff_utm_source) {
61            return true
62        }
63        return false
64    },
65    track: function() {
66        var a = this.get_param(this.aff_sid_param);
67        var b = this.get_param(this.aff_source_param);
68        console.log('_aff_sid 1', b);
69
70        // Không có aff_sid -> không làm gì, giữ nguyên cookie cũ
71        if (!a) return;
72
73        console.log('_aff_sid 2', b);
74        if (this.is_lastclick) {
75            // Last-click: luôn ghi đè bất kể source
76            if (b) {
77                this.set_cookie("_aff_network", b, this.cookie_duration);
78            } else {
79                this.set_cookie("_aff_network", "", 0); // clear nếu aff_sid mới không có source
80            }
81            console.log('_aff_sid 3', a);
82            this.set_cookie("_aff_sid", a, this.cookie_duration);
83        } else {
84            // First-click: chỉ lưu nếu chưa có cookie
85            if (!this.get_cookie("_aff_network")) {
86                if (b) {
87                    this.set_cookie("_aff_network", b, this.cookie_duration);
88                } else {
89                    this.set_cookie("_aff_network", "", 0); // clear nếu aff_sid mới không có source
90                }
91                console.log('_aff_sid 4', a);
92                this.set_cookie("_aff_sid", a, this.cookie_duration);
93            }
94        }
95    },
96    is_in_app_browser: function() {
97        var a = navigator.userAgent || "";
98        if (a.match(/FBAN\/FBIOS/i)) {
99            return true
100        }
101        if (a.match(/FBAN\/MessengerForiOS/i)) {
102            return true
103        }
104        if (a.match(/FBMD\/iPhone/i)) {
105            return true
106        }
107        if (a.match(/FBSN\/iOS/i)) {
108            return true
109        }
110        return false
111    },
112    track_order: function(p) {
113        var d = p.order_items ? p.order_items : [];
114        var f = p.order_id ? p.order_id : "";
115        var k = p.amount ? p.amount : 0;
116        var m = p.discount ? p.discount : 0;
117        var t = "";
118        var o = this.get_cookie("_aff_network");
119        var r = this.get_cookie("_aff_sid");
120        var h = [];
121        var g = "";
122        var e = d.length;
123        for (var q = 0; q < e; q++) {
124            var l = d[q].itemid;
125            var j = d[q].quantity;
126            var n = d[q].price;
127            var c = d[q].catid;
128            var s = d[q].cat_name ? d[q].cat_name : "";
129            t += ("&product[]=$id:" + l + "$quantity:" + j + "$price:" + n + "$category_id:" + c + "$category_name:" + s)
130        }
131        if (p.extra__phone) {
132            h.push("extra__phone=" + p.extra__phone)
133        }
134        if (p.extra__commission) {
135            h.push("extra__commission=" + p.extra__commission)
136        }
137        if (p.extra__share_percent) {
138            h.push("extra__share_percent=" + p.extra__share_percent)
139        }
140        if (h.length > 0) {
141            g = "&" + h.join("&")
142        }
143        var b = "https://track.accesstrade.vn/track/collector?transaction_id=" + f;
144        b += "&tracking_id=" + r + "&aff_source=" + o;
145        b += "&campaign_id=" + this.campaign_id + "&result_id=" + this.result_id;
146        b += "&amount=" + k + "&discount=" + m + t + g;
147        if (!navigator.sendBeacon || this.is_in_app_browser()) {
148            var u = document.createElement("img");
149            u.width = 1;
150            u.height = 1;
151            u.border = 0;
152            u.src = b;
153            document.body.appendChild(u);
154            console.log("[AT] Pixel tracking url: " + u.src)
155        } else {
156            navigator.sendBeacon(b);
157            console.log("[AT] Postback tracking url: " + b)
158        }
159        if (!this.is_reoccur) {
160            console.log('xoa cookie aff_sid');
161            this.set_cookie("_aff_network", "", 0);
162            this.set_cookie("_aff_sid", "", 0)
163        }
164    },
165    get_param: function(c, b) {
166        if (!b) {
167            b = location.href
168        }
169        c = c.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
170        var a = "[\\?&]" + c + "=([^&#]*)";
171        var e = new RegExp(a);
172        var d = e.exec(b);
173        return d == null ? null : d[1]
174    },
175    set_cookie: function(g, b, c) {
176        var f = new Date();
177        f.setTime(f.getTime() + (c * 24 * 60 * 60 * 1000));
178        var a = "expires=" + f.toUTCString();
179        cookie_domain = this.cookie_domain || window.location.hostname;
180        document.cookie = g + "=" + b + "; " + a + ";domain=" + cookie_domain + "; path=/"
181    },
182    get_cookie: function(d) {
183        var b = d + "=";
184        var a = document.cookie.split(";");
185        for (var e = 0; e < a.length; e++) {
186            var f = a[e];
187            while (f.charAt(0) == " ") {
188                f = f.substring(1)
189            }
190            if (f.indexOf(b) == 0) {
191                return f.substring(b.length, f.length)
192            }
193        }
194        return undefined
195    }
196};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.