Skip to content

Commit

Permalink
Added some basic URL tracking so we can judge referrals to the website.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pickysaurus committed Oct 14, 2024
1 parent 72c7708 commit 0c339b8
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 384 deletions.
6 changes: 3 additions & 3 deletions src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryResult } from 'pg';
import { NexusUser, NexusLinkedMod } from '../types/users';
import { Client, EmbedBuilder, User, Snowflake } from 'discord.js';
import { getModsbyUser } from './bot-db';
import { logMessage } from './util';
import { logMessage, nexusModsTrackingUrl } from './util';
import { DiscordBotUser } from './DiscordBotUser';

async function getAllUsers(): Promise<NexusUser[]> {
Expand Down Expand Up @@ -183,7 +183,7 @@ async function userProfileEmbed(user: DiscordBotUser, client: Client): Promise<E
.setAuthor({ name: "Member Search Results", iconURL: discordUser.avatarURL() || undefined})
.addFields({
name: "Nexus Mods",
value: `[${user.NexusModsUsername}](https://nexusmods.com/users/${user.NexusModsId})\n${roleToShow}`,
value: `[${user.NexusModsUsername}](${nexusModsTrackingUrl(`https://nexusmods.com/users/${user.NexusModsId}`, 'profile')})\n${roleToShow}`,
inline: true
})
.addFields({ name: "Discord", value: `${discordUser.toString()}\n${discordUser.tag}`, inline: true})
Expand All @@ -192,7 +192,7 @@ async function userProfileEmbed(user: DiscordBotUser, client: Client): Promise<E
.setTimestamp(user.LastUpdated)
.setFooter({ text: 'Nexus Mods API link', iconURL: client.user?.avatarURL() || ''});
if (mods && mods.length) {
let modData = mods.sort(modsort).map( mod => `[${mod.name}](https://nexusmods.com/${mod.path}) - ${mod.game}`);
let modData = mods.sort(modsort).map( mod => `[${mod.name}](${nexusModsTrackingUrl(`https://nexusmods.com/${mod.path}`, 'profile')}) - ${mod.game}`);
if (modData.length > 5) modData = modData.slice(0,4); //Only show a maximum of 5.
embed.addFields({ name: `My Mods - ${totalDownloads(mods).toLocaleString()} downloads for ${mods.length} mod(s).`, value: `${modData.join("\n")}\n-----\n[**See all of ${user.NexusModsUsername}'s content at Nexus Mods.**](https://www.nexusmods.com/users/${user.NexusModsId}?tab=user+files)`})
}
Expand Down
9 changes: 9 additions & 0 deletions src/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ export const discontinuedEmbed = (newCommand: string): EmbedBuilder => {
.setTitle('Command discontinued')
.setColor('Grey')
.setDescription(`This command has been retired, please use the slash command **${newCommand}** instead. [Help](https://discord.gg/nexusmods)`)
}

export const nexusModsTrackingUrl = (url: string, tag?: string): string => {
const campaign = 'DiscordBot';
const params = new URLSearchParams();
params.append('mtm_campaign', campaign);
if (tag) params.append('mtm_kwd', tag);

return new URL(`${url}?${params.toString()}`).toString();
}
6 changes: 3 additions & 3 deletions src/feeds/GameFeedManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAllGameFeeds, getGameFeed, createGameFeed, deleteGameFeed, getUserBy
import { ClientExt } from "../types/DiscordTypes";
import { IUpdateEntry, IChangelogs } from '@nexusmods/nexus-api';
import { User, Guild, Snowflake, TextChannel, WebhookClient, GuildMember, EmbedBuilder, Client, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle, NewsChannel, GuildBasedChannel } from 'discord.js';
import { logMessage } from '../api/util';
import { logMessage, nexusModsTrackingUrl } from '../api/util';
import { NexusAPIServerError } from '../types/util';
import { DiscordBotUser } from '../api/DiscordBotUser';
import { IMod } from '../api/queries/v2';
Expand Down Expand Up @@ -369,13 +369,13 @@ function createModEmbedGQL(client: Client,
compact: boolean): EmbedBuilder {
const gameThumb: string = `https://staticdelivery.nexusmods.com/Images/games/4_3/tile_${game.id}.jpg`;
const category: string = mod.modCategory.name || 'Unknown';
const uploaderProfile: string = `https://nexusmods.com/${game.domain_name}/users/${mod.uploader.memberId}`;
const uploaderProfile: string = nexusModsTrackingUrl(`https://nexusmods.com/${game.domain_name}/users/${mod.uploader.memberId}`, 'gamefeed');

let post = new EmbedBuilder()
.setAuthor({name:`${newMod ? 'New Mod Upload' : 'Updated Mod'} (${game.name})`, iconURL: client.user?.avatarURL() || '' })
.setTitle(mod.name || 'Name not found')
.setColor(newMod ? 0xda8e35 : 0x57a5cc)
.setURL(`https://www.nexusmods.com/${mod.game.domainName}/mods/${mod.modId}`)
.setURL(nexusModsTrackingUrl(`https://www.nexusmods.com/${mod.game.domainName}/mods/${mod.modId}`, 'gamefeed'))
.setDescription(sanitizeBreaks(mod.summary || 'No summary'))
.setImage(!compact? mod.pictureUrl || null : null)
.setThumbnail(compact ? mod.pictureUrl || null : gameThumb)
Expand Down
4 changes: 2 additions & 2 deletions src/interactions/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { customEmojis } from "../types/util";
import { DiscordInteraction } from '../types/DiscordTypes';
import { getUserByDiscordId, getServer } from '../api/bot-db';
import Fuse from 'fuse.js';
import { logMessage } from "../api/util";
import { logMessage, nexusModsTrackingUrl } from "../api/util";
import { CollectionsFilter } from "../types/GQLTypes";
import { BotServer } from "../types/servers";
import { sendUnexpectedError } from '../events/interactionCreate';
Expand Down Expand Up @@ -454,7 +454,7 @@ const singleModEmbed = (client: Client, mod: IMod|undefined, game?: IGameStatic)

if (mod) {
embed.setTitle(mod.name || 'Mod name unavailable')
.setURL(`https://nexusmods.com/${mod.game.domainName}/mods/${mod.modId}`)
.setURL(nexusModsTrackingUrl(`https://nexusmods.com/${mod.game.domainName}/mods/${mod.modId}`, 'search'))
.setDescription(`${game ? `**Game:** [${game?.name}](https://nexusmods.com/${game.domain_name})\n**Category:** ${mod.modCategory.name}\n` : ''}**Version:** ${mod.version}\n\n${mod.summary?.replace(/\<br \/\>/g, '\n')}`)
.setTimestamp(new Date(mod.updatedAt))
.setImage(mod.pictureUrl || '')
Expand Down
Loading

0 comments on commit 0c339b8

Please sign in to comment.