You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/activities/Development_Guides.mdx
+70-17Lines changed: 70 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -887,34 +887,87 @@ This example is being done entirely on the client, however, a more common patter
887
887
---
888
888
889
889
### Prompting Users to Share Incentivized Links
890
-
Virality is a valuable way to grow your userbase and your application. In order to leverage network effects, we suggest using our SDK's `shareLink` command to prompt users to share so-called "incentivized links" and receive rewards for sharing.
891
890
892
-
An example reward would be something like free coins (or any other in-game resource) for users who click the link and for those who shared the link.
891
+
Incentivized sharing can help grow your application through network effects. This guide covers implementing a reward system for users who share links and those who click them.
892
+
893
+
#### Implementation Overview
894
+
1. Create and track promotional campaigns
895
+
2. Prompt users to share links
896
+
3. Handle incoming referrals
897
+
4. Distribute rewards safely
898
+
899
+
#### Sharing Links
900
+
901
+
When implementing sharing, you'll need to:
902
+
1. Generate a unique ID for tracking the promotion
903
+
2. Call the `shareLink` command
904
+
3. Track the share attempt
893
905
894
-
To share the link, use `shareLink`.
895
906
```javascript
896
-
// custom ID creation, persistence, and resolution is up to you as a developer
907
+
// Generate a unique ID for this promotion
908
+
// This could be per-campaign, per-user, or per-share depending on your needs
message:'Click this link to redeem 5 free coins!',
914
+
custom_id: customId,
915
+
// referrer_id is optional - if omitted, the current user's ID is used
916
+
});
917
+
918
+
if (success) {
919
+
// Track successful share for analytics/limiting
920
+
awaittrackSuccessfulShare(customId);
921
+
}
922
+
} catch (error) {
923
+
// Handle share failures appropriately
924
+
console.error('Failed to share link:', error);
925
+
}
904
926
```
905
-
Calling `shareLink` will prompt the user with a modal to share the link. The `success` returned indicates if the link was shared or copied. Note that we did not add a `referrer_id` in this example, as the user ID of the user sharing the link will automatically be appended as a referrer if left empty.
906
927
907
-
So now that the initial user has shared a link, what happens when their friend receives the message and clicks the link?
908
-
Clicking the link (or Play from the Embed) will launch the activity and pass the `customId` and `referredId` to the SDK. Once launched, the SDK will expose the `customId` and `refererId` and you can resolve the IDs and grant the rewards as promised.
928
+
#### Handling Incoming Referrals
929
+
When a user clicks a shared link, your activity will launch with referral data available through the SDK:
909
930
910
931
```javascript
911
-
// for illustrative purposes -- this must be implemented by you as a developer
912
-
awaitresolvePromotion({
913
-
customId:DiscordRPC.customId, // your promotional ID, which corresponds to granting reward (coins)
914
-
refererId:DiscordRPC.referredId, // the user ID of the initial user who shared the link
915
-
});
932
+
// Early in your activity's initialization
933
+
asyncfunctionhandleReferral() {
934
+
// Validate the referral data
935
+
if (!DiscordRPC.customId||!DiscordRPC.refererId) {
936
+
return;
937
+
}
938
+
939
+
try {
940
+
// Verify this is a valid promotion and hasn't expired
console.error('Failed to process referral:', error);
961
+
}
962
+
}
916
963
```
917
964
965
+
#### Link Sharing Best Practices
966
+
- Generate unique, non-guessable `customId`s
967
+
- Track and validate referrals to prevent abuse
968
+
- Handle edge cases like expired promotions gracefully
969
+
- Consider implementing cool-down periods between shares
970
+
918
971
### Preventing unwanted activity sessions
919
972
920
973
Activities are surfaced through iframes in the Discord app. The activity website itself is publicly reachable at `<application_id>.discordsays.com`. Activities will expect to be able to communicate with Discord's web or mobile client via the Discord SDK's RPC protocol. If a user loads the activity's website in a normal browser, the Discord RPC server will not be present, and the activity will likely fail in some way.
0 commit comments