Skip to content

Commit

Permalink
➕ Use nuxt-facebook-pixel-module for fbq
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Nov 13, 2024
1 parent 12561ec commit a3dd1d1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
env:
GA_TRACKING_ID: ${{ vars.GA_TRACKING_ID }}
AD_CONVERSION_ID: ${{ vars.AD_CONVERSION_ID }}
FACEBOOK_PIXEL_ID: ${{ vars.FACEBOOK_PIXEL_ID }}
STRIPE_PUBLIC_KEY: ${{ vars.STRIPE_PUBLIC_KEY }}
CRISP_WEBSITE_ID: ${{ vars.CRISP_WEBSITE_ID }}
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
Expand Down
9 changes: 9 additions & 0 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"magic-grid": "^3.2.4",
"marked": "^5.1.2",
"node-fetch": "^2.6.7",
"nuxt-facebook-pixel-module": "^1.6.0",
"nuxt-start": "^2.17.2",
"portal-vue": "^1.5.1",
"querystring": "^0.2.1",
Expand Down
2 changes: 2 additions & 0 deletions src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const { IS_TESTNET } = process.env;

export const { AD_CONVERSION_ID } = process.env;

export const { FACEBOOK_PIXEL_ID } = process.env;

export const TEST_MODE =
process.env.NODE_ENV !== 'production' || process.env.CI;

Expand Down
13 changes: 11 additions & 2 deletions src/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
GA_TRACKING_ID,
AD_CONVERSION_ID,
EXTERNAL_URL,
FACEBOOK_PIXEL_ID,
} = process.env;

const nuxtConfig = {
Expand All @@ -23,6 +24,7 @@ const nuxtConfig = {
STRIPE_PUBLIC_KEY,
GA_TRACKING_ID,
AD_CONVERSION_ID,
FACEBOOK_PIXEL_ID,
SITE_NAME,
EXTERNAL_URL,
},
Expand Down Expand Up @@ -86,7 +88,6 @@ const nuxtConfig = {
],
link: [
{ rel: 'preconnect', href: 'https://storage.googleapis.com' },
{ rel: 'preload', href: '/vendor/fbq.js', as: 'script' },
{
hid: 'stripe-js-link',
rel: 'preload',
Expand Down Expand Up @@ -134,7 +135,6 @@ const nuxtConfig = {
})),
],
script: [
{ src: '/vendor/fbq.js', type: 'text/javascript', async: true },
{
hid: 'stripe-js-script',
src: 'https://js.stripe.com/v3',
Expand Down Expand Up @@ -330,6 +330,15 @@ const nuxtConfig = {
'@nuxtjs/sentry',
'@nuxtjs/sitemap',
'portal-vue/nuxt',
[
'nuxt-facebook-pixel-module',
{
track: 'PageView',
pixelId: FACEBOOK_PIXEL_ID || '0',
autoPageView: true,
disabled: !FACEBOOK_PIXEL_ID,
},
],
// [
// '@likecoin/nuxt-google-optimize',
// {
Expand Down
11 changes: 10 additions & 1 deletion src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"marked": "^5.1.2",
"node-fetch": "^2.6.0",
"nuxt": "^2.17.2",
"nuxt-facebook-pixel-module": "^1.6.0",
"portal-vue": "^2.1.7",
"postcss": "^8.4.14",
"querystring": "^0.2.1",
Expand Down
11 changes: 0 additions & 11 deletions src/static/vendor/fbq.js

This file was deleted.

23 changes: 11 additions & 12 deletions src/util/EventLogger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IS_TESTNET, AD_CONVERSION_ID } from '../constant';
import { IS_TESTNET, AD_CONVERSION_ID, FACEBOOK_PIXEL_ID } from '../constant';

function hexString(buffer) {
const byteArray = new Uint8Array(buffer);
Expand Down Expand Up @@ -28,8 +28,8 @@ export function resetLoggerUser(vue) {
vue.$gtag.set({ userId: null });
vue.$gtag.set({ user_id: null });
}
if (window.fbq && window.PIXEL_ID && !IS_TESTNET) {
window.fbq('init', window.PIXEL_ID);
if (vue.$fb && FACEBOOK_PIXEL_ID) {
vue.$fb.init(FACEBOOK_PIXEL_ID);
}
if (vue.$crisp) {
vue.$crisp.push(['do', 'session:reset']);
Expand Down Expand Up @@ -65,8 +65,8 @@ export async function setLoggerUser(
// vue.$gtag.config({ user_id: hashedId });
vue.$gtag.set({ user_id: hashedId });
}
if (window.fbq && window.PIXEL_ID && !IS_TESTNET) {
window.fbq('init', window.PIXEL_ID, {
if (vue.$fb && FACEBOOK_PIXEL_ID) {
vue.$fb.init(FACEBOOK_PIXEL_ID, {
external_id: wallet,
});
}
Expand Down Expand Up @@ -96,8 +96,8 @@ export function updateLoggerUserInfo(
if (vue.$gtag) {
if (email) vue.$gtag.set('user_data', { email });
}
if (window.fbq && window.PIXEL_ID && !IS_TESTNET) {
window.fbq('init', window.PIXEL_ID, {
if (vue.$fb && FACEBOOK_PIXEL_ID) {
vue.$fb.init(FACEBOOK_PIXEL_ID, {
em: email,
external_id: wallet,
});
Expand Down Expand Up @@ -201,7 +201,7 @@ export function logPurchaseFlowEvent(
});
}
}
if (window.fbq && !IS_TESTNET) {
if (vue.$fb && FACEBOOK_PIXEL_ID) {
const eventNameMapping = {
view_item: 'ViewContent',
begin_checkout: 'InitiateCheckout',
Expand All @@ -212,8 +212,7 @@ export function logPurchaseFlowEvent(
if (eventNameMapping[event]) {
const eventName = eventNameMapping[event];
const eventID = paymentId ? `${eventName}_${paymentId}` : undefined;
window.fbq(
'track',
vue.$fb.track(
eventName,
{
currency,
Expand Down Expand Up @@ -294,8 +293,8 @@ export function logPurchaseNFTBookEvent(
],
});
}
if (window.fbq && !IS_TESTNET) {
window.fbq('trackCustom', 'PurchaseBook', {
if (vue.$fb && FACEBOOK_PIXEL_ID) {
vue.$fb.query('trackCustom', 'PurchaseBook', {
currency,
value: price,
content_type: 'product',
Expand Down

0 comments on commit a3dd1d1

Please sign in to comment.