Skip to content

Commit

Permalink
📈 Setup explicit ad conversion event
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Sep 23, 2024
1 parent ea5fa61 commit 8d372d9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- run: firebase deploy --project civic-liker -f
env:
GA_TRACKING_ID: ${{ vars.GA_TRACKING_ID }}
AD_CONVERSION_ID: ${{ vars.AD_CONVERSION_ID }}
STRIPE_PUBLIC_KEY: ${{ vars.STRIPE_PUBLIC_KEY }}
CRISP_WEBSITE_ID: ${{ vars.CRISP_WEBSITE_ID }}
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-rinkeby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- run: firebase deploy --project civic-liker-develop -f
env:
GA_TRACKING_ID: ${{ vars.GA_TRACKING_ID }}
AD_CONVERSION_ID: ${{ vars.AD_CONVERSION_ID }}
CRISP_WEBSITE_ID: ${{ vars.CRISP_WEBSITE_ID }}
STRIPE_PUBLIC_KEY: ${{ vars.STRIPE_PUBLIC_KEY }}
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
Expand Down
2 changes: 1 addition & 1 deletion src/constant/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const { IS_TESTNET } = process.env;
export const { IS_TESTNET, AD_CONVERSION_ID } = process.env;

export const TEST_MODE =
process.env.NODE_ENV !== 'production' || process.env.CI;
Expand Down
4 changes: 2 additions & 2 deletions src/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
CRISP_WEBSITE_ID,
STRIPE_PUBLIC_KEY,
GA_TRACKING_ID,
ADWORDS_TRACKING_ID,
AD_CONVERSION_ID,
EXTERNAL_URL,
} = process.env;

Expand All @@ -22,7 +22,7 @@ const nuxtConfig = {
CRISP_WEBSITE_ID,
STRIPE_PUBLIC_KEY,
GA_TRACKING_ID,
ADWORDS_TRACKING_ID,
AD_CONVERSION_ID,
SITE_NAME,
EXTERNAL_URL,
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/nft/claim/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ export default {
price,
currency: 'USD',
isNFTBook: true,
paymentId: this.paymentId,
});
items.forEach(item => {
logPurchaseNFTBookEvent(this, {
Expand Down
1 change: 1 addition & 0 deletions src/pages/nft/gift/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default {
price,
currency: 'USD',
isNFTBook: true,
paymentId: this.paymentId,
});
logPurchaseNFTBookEvent(this, {
name: this.productName,
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/gtag.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export default (ctx, inject) => {
} = ctx;
if (process.env.GA_TRACKING_ID) {
const includes = [];
if (process.env.ADWORDS_TRACKING_ID) {
includes.push({ id: process.env.ADWORDS_TRACKING_ID });
}
Vue.use(
VueGtag,
{
Expand Down
14 changes: 11 additions & 3 deletions src/util/EventLogger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IS_TESTNET } from '../constant';
import { IS_TESTNET, AD_CONVERSION_ID } from '../constant';

function hexString(buffer) {
const byteArray = new Uint8Array(buffer);
Expand Down Expand Up @@ -126,7 +126,7 @@ export function logTrackerEvent(
export function logPurchaseFlowEvent(
vue,
event,
{ txHash, price, currency, items, isNFTBook }
{ txHash, price, currency, items, isNFTBook, paymentId }
) {
try {
if (
Expand All @@ -144,7 +144,7 @@ export function logPurchaseFlowEvent(
}
if (vue.$gtag) {
vue.$gtag.event(event, {
transaction_id: txHash,
transaction_id: paymentId || txHash,
value: price,
currency,
items: items.map(i => {
Expand All @@ -159,6 +159,14 @@ export function logPurchaseFlowEvent(
};
}),
});
if (event === 'purchase' && AD_CONVERSION_ID) {
vue.$gtag.event('conversion', {
send_to: AD_CONVERSION_ID,
value: price,
currency: 'USD',
transaction_id: paymentId || txHash,
});
}
}
if (window.fbq && !IS_TESTNET) {
const eventNameMapping = {
Expand Down

0 comments on commit 8d372d9

Please sign in to comment.