Skip to main content

Getting Campaign Data

The AppTrove Unity SDK provides functions to retrieve campaign-related data, such as ad identifiers, campaign names, and click IDs, enabling personalized user experiences and detailed analytics. This section outlines how to access campaign data using the SDK.

Prerequisites

  • AppTrove Unity SDK installed and initialized in your Unity project (see Installation and Initialization)
  • A Trackier MMP account with access to the Trackier Panel
  • Unity Editor 2019.4 or later
  • Basic knowledge of C# scripting

Retrieve Campaign Data

The SDK offers methods to access various campaign attributes, which can be used to tailor user experiences or analyze campaign performance. These attributes include ad IDs, campaign IDs, channels, and custom parameters.

Steps to Retrieve Campaign Data

  1. Ensure the SDK is initialized in your Unity project.
  2. Use the provided TrackierUnity methods to retrieve specific campaign data attributes.
  3. Optionally, integrate the retrieved data with an event or use it for in-app personalization.
main.cs
using UnityEngine;
using com.trackier.sdk;

namespace com.sampleapp
{
public class Script : MonoBehaviour
{
void Start()
{
// Initialize SDK
TrackierConfig trackierConfig = new TrackierConfig("e69b921c-bbe8-xxxx-xxxx-5a9678abffea", "development");
trackierConfig.setAppSecret("6419510xxxxxxxa686cf1", "MzgwYWMwOTQt6xxxxxxxxxxxxxxtZTk3MTMwNTMzMjQ5");
TrackierUnity.initialize(trackierConfig);

// Retrieve Campaign Data
TrackierEvent trackierEvent = new TrackierEvent(TrackierEvent.PURCHASE);
string ad = TrackierUnity.getAd();
string adID = TrackierUnity.getAdID();
string adSet = TrackierUnity.getAdSet();
string adSetID = TrackierUnity.getAdSetID();
string campaign = TrackierUnity.getCampaign();
string campaignID = TrackierUnity.getCampaignID();
string channel = TrackierUnity.getChannel();
string clickId = TrackierUnity.getClickId();
string p1 = TrackierUnity.getP1();
string p2 = TrackierUnity.getP2();
string p3 = TrackierUnity.getP3();
string p4 = TrackierUnity.getP4();
string p5 = TrackierUnity.getP5();
string dlv = TrackierUnity.getDlv();
string pid = TrackierUnity.getPid();
string retargeting = TrackierUnity.getIsRetargeting();
TrackierUnity.trackierEvent(trackierEvent);

// Example: Log campaign data for debugging
Debug.Log($"Campaign: {campaign}, Click ID: {clickId}, Ad ID: {adID}");
}

void Update()
{
}
}
}

Available Methods

The following methods retrieve campaign-related data:

  • TrackierUnity.getAd(): Returns the ad name.
  • TrackierUnity.getAdID(): Returns the ad ID.
  • TrackierUnity.getAdSet(): Returns the ad set name.
  • TrackierUnity.getAdSetID(): Returns the ad set ID.
  • TrackierUnity.getCampaign(): Returns the campaign name.
  • TrackierUnity.getCampaignID(): Returns the campaign ID.
  • TrackierUnity.getChannel(): Returns the channel name.
  • TrackierUnity.getClickId(): Returns the click ID.
  • TrackierUnity.getP1() to TrackierUnity.getP5(): Returns custom parameters (P1 to P5).
  • TrackierUnity.getDlv(): Returns the deep link value.
  • TrackierUnity.getPid(): Returns the partner ID.
  • TrackierUnity.getIsRetargeting(): Returns whether the campaign is for retargeting.

Expected Outcome

The retrieved campaign data can be used for analytics, personalization, or debugging. For example, you can log the data, store it for later use, or include it in events tracked via TrackierUnity.trackierEvent.

Best Practices

  • Validate Data: Check for null or empty values when retrieving campaign data to avoid runtime errors.
  • Use for Personalization: Leverage campaign data (e.g., campaign, adID) to customize user experiences, such as displaying targeted content.
  • Log for Debugging: Use Debug.Log to verify retrieved data during development, especially in the "development" environment.
  • Integrate with Events: Combine campaign data with event tracking (e.g., TrackierEvent) to enrich analytics in the Trackier Panel.
  • Comply with Privacy Regulations: Ensure campaign data handling complies with GDPR, CCPA, and other privacy laws, especially for user-specific data like clickId.
  • Test in Development Mode: Use the "development" environment to test campaign data retrieval without affecting production analytics.

Troubleshooting

  • Campaign Data Returns Null or Empty:
    • Ensure the SDK is initialized before calling campaign data methods.
    • Verify that the campaign is correctly set up in the Trackier Panel and associated with the app.
    • Check Unity Console logs for errors related to TrackierUnity methods.
  • Incorrect Campaign Data:
    • Confirm the SDK key and environment match the Trackier Panel configuration.
    • Ensure the campaign data is populated in the Trackier MMP for the specific user or click.

For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.