-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfacebook-pixel.js
41 lines (39 loc) · 960 Bytes
/
facebook-pixel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-disable */
export default ({ app }) => {
/*
** Only run on client-side and only in production mode
*/
if (process.env.NODE_ENV !== "production") return;
/*
** Initialize Facebook Pixel Script
*/
!(function(f, b, e, v, n, t, s) {
if (f.fbq) return;
n = f.fbq = function() {
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
};
if (!f._fbq) f._fbq = n;
n.push = n;
n.loaded = !0;
n.version = "2.0";
n.queue = [];
t = b.createElement(e);
t.async = !0;
t.src = v;
s = b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t, s);
})(
window,
document,
"script",
"https://connect.facebook.net/en_US/fbevents.js"
);
fbq("init", "YOUR_FACEBOOK_PIXEL_ID");
app.router.afterEach((to, from) => {
/*
** Fire a page view on each route change
*/
console.log("fire pageview");
fbq("track", "PageView");
});
};