-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added messageReaction tracking with GA
- Loading branch information
1 parent
ab00d4f
commit a38d613
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import ga from './ga.js' | ||
|
||
export default async function gaMessageReactionAdd ( messageReaction, user ){ | ||
|
||
if( !messageReaction?.message?.guildId || !user ){ | ||
throw new Error(`Parameters required => message.guildId: ${ !!messageReaction?.message?.guildId ? '✅' : '❌' }, user.id: ${ !!user?.id ? '✅' : '❌' }.`) | ||
} | ||
|
||
//create an event and send to ga using the ga function | ||
const guildId = messageReaction?.message?.guildId; | ||
|
||
// A queue to batch our events | ||
const events = []; | ||
|
||
// Let's push the page view event | ||
events.push({ | ||
//name: 'message_sent', | ||
name: 'page_view', | ||
params: { | ||
page_title: `discord-channel-${messageReaction?.message?.channelId}`, // REPLACE WITH CHANNEL NAME IF NO BOTTLENECK | ||
//page_location: `https://discordlinks.com/discord/channel/${message.channelId}`, | ||
page_location: `https://discord.com/channels/${messageReaction?.message?.guildId}/${messageReaction?.message?.channelId}`, | ||
guild_id: messageReaction?.message?.guildId, | ||
channel_id: messageReaction?.message?.channelId, | ||
//raw_url: `https://discord.com/channels/${guildId}/${channelId}`, | ||
//language: "en", | ||
//page_referrer: "apple.com", | ||
//screen_resolution: "" | ||
engagement_time_msec: "1" // Needed for non-zero user count | ||
}, | ||
}); | ||
|
||
|
||
// Let's push the message_sent event | ||
events.push({ | ||
//name: 'message_sent', | ||
name: 'message_reaction_add', | ||
params: { | ||
page_title: `discord-channel-${messageReaction?.message?.channelId}`, | ||
page_location: `https://discord.com/channels/${messageReaction?.message?.guildId}/${messageReaction?.message?.channelId}`, | ||
emoji_name: messageReaction?._emoji.name, | ||
//emoji_id: messageReaction?._emoji.id, // can be NULL => event is not processed in GA if one property is NULL | ||
//emoji_animated: messageReaction?._emoji.animated, // can be NULL => event is not processed in GA if one property is NULL | ||
guild_id: messageReaction?.message?.guildId, | ||
channel_id: messageReaction?.message?.channelId, | ||
author_id: messageReaction?.message?.author?.id, | ||
message_lenght: messageReaction?.message?.content.length, | ||
message_url: `https://discord.com/channels/${messageReaction?.message?.guildId}/${messageReaction?.message?.channelId}/${messageReaction?.message?.id}`, | ||
//language: "en", | ||
//page_referrer: "apple.com", | ||
//screen_resolution: "" | ||
//engagement_time_msec: "1" // Needed for non-zero user count | ||
}, | ||
}); | ||
|
||
// Send the events to GA using our measurementId and apiSecret | ||
if (messageReaction?.message?.content.length) { | ||
const debug = await ga ( guildId, null, user, events, false ); | ||
console.log('debug: ', debug) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Events } from 'discord.js'; | ||
import gaMessageReactionAdd from '../../analytics/gaMessageReactionAdd.js' | ||
import Member from '../../mongodb/models/members.js'; | ||
import discordToMongoId from '../../mongodb/utils/idConversion/discordToMongoId.js'; | ||
import saveMessage from '../../mongodb/utils/saveMessage.js'; | ||
import ga from '../../analytics/ga.js'; | ||
import gaMessageSent from '../../analytics/gaMessageSent.js' | ||
|
||
export const event = { | ||
name: Events.MessageReactionAdd, | ||
async execute( messageReaction , user ) { | ||
|
||
try { | ||
|
||
// fetch the message if it's not cached | ||
const message = !messageReaction.message.author | ||
? await messageReaction.message.fetch() | ||
: messageReaction.message; | ||
|
||
// Sending a message_sent event to Google Analytics | ||
gaMessageReactionAdd( messageReaction, user ); | ||
|
||
console.log( 'messageReaction', messageReaction ); | ||
console.log( 'user', user) | ||
|
||
} catch (e) { | ||
console.warn('Error on messageReactionAdd event: ', e); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters