Preventing Blocked HTTP Traffic with CNAME

Ad-blocking technologies sometimes block mParticle tags and event collection endpoints. To prevent blocking and ensure maximum data collection, configure a first-party domain for event collection, and use it instead of the SDK default mparticle.com domain.

To prevent this blocked HTTP traffic, create a custom subdomain and point that DNS record to mParticle. Traffic is less likely to be blocked because the domain used for mParticle traffic matches the root domain used in your app.

Use this process to create a custom subdomain and point the DNS record to mParticle:

  1. Choose a subdomain and provide this to mParticle. For example, mp.mydomain.com or mparticle.mydomain.com. To contact mParticle, visit the mParticle Support site and submit a request.
  2. In order for mParticle to obtain an SSL certificate, the certificate provider must prove domain ownership. mParticle provides a DNS record to be inserted into the customer’s public DNS server. This might either be a TXT or CNAME record.
  3. Once step 2 is complete, mParticle Operations verifies the domain and obtains the SSL certificate.
  4. mParticle provides the CNAME value to you, and you point your chosen subdomain from step 1 to this value.
  5. mParticle uses Fastly as our CDN and edge delivery network. In the event that the customer is also a Fastly customer, and the root domain in question (mydomain.com in this example) has been configured previously, Fastly will need to obtain permission from the account owner or authorized point of contact prior to allowing mParticle to complete provisioning. In this case, an additional TXT DNS record will need to be created. Further details will be provided by mParticle at such time.
  6. Update your SDK configuration snippets to include the relevant custom CNAME endpoints for uploads as shown in the following example snippet.

iOS SDK Config Snippet

    MParticleOptions *options = [MParticleOptions optionsWithKey:@"REPLACE WITH APP KEY" secret:@"REPLACE WITH APP SECRET"];
    options.logLevel = MPILogLevelDebug;
    MPNetworkOptions *networkOptions = [[MPNetworkOptions alloc] init];
    
    // maps mp.example.com/config/v4 to config2.mparticle.com/v4
    networkOptions.configHost = @"mp.example.com/config/v4";
    networkOptions.overridesConfigSubdirectory = YES;
    
    // maps mp.example.com/nativeevents/v2 to nativesdks.mparticle.com/v2
    networkOptions.eventsHost = @"mp.example.com/nativeevents/v2";
    networkOptions.overridesEventsSubdirectory = YES;
    
    // maps mp.example.com/identity/v1 to identity.mparticle.com/v1
    networkOptions.identityHost = @"mp.example.com/identity/v1";
    networkOptions.overridesIdentitySubdirectory = YES;
    
    // maps mp.example.com/nativeevents/v1/identity to nativesdks.mparticle.com/v1/identity
    networkOptions.aliasHost = @"mp.example.com/nativeevents/v1/identity";
    networkOptions.overridesAliasSubdirectory = YES;

    // The Godaddy and LetsEncrypt root certificates that mParticle uses are already included in
    // the SDK, so the following lines are only needed if you are using your own certificate provider.
    networkOptions.certificates = @[ @"your root certificate" ];
    options.networkOptions = networkOptions;
    [[MParticle sharedInstance] startWithOptions:options];
    let options = MParticleOptions(key: "REPLACE WITH APP KEY", secret: "REPLACE WITH APP SECRET")
    options.logLevel = .verbose

    let networkOptions = MPNetworkOptions()
    
    // maps mp.example.com/config/v4 to config2.mparticle.com/v4
    networkOptions.configHost = "mp.example.com/config/v4"
    networkOptions.overridesConfigSubdirectory = true
    
    // maps mp.example.com/nativeevents/v2 to nativesdks.mparticle.com/v2
    networkOptions.eventsHost = "mp.example.com/nativeevents/v2"
    networkOptions.overridesEventsSubdirectory = true
    
    // maps mp.example.com/identity/v1 to identity.mparticle.com/v1
    networkOptions.identityHost = "mp.example.com/identity/v1" 
    networkOptions.overridesIdentitySubdirectory = true
    
    // maps mp.example.com/nativeevents/v1/identity to nativesdks.mparticle.com/v1/identity
    networkOptions.aliasHost = "mp.example.com/nativeevents/v1/identity" 
    networkOptions.overridesAliasSubdirectory = true

    // The Godaddy and LetsEncrypt root certificates that mParticle uses are already included in
    // the SDK, so the following lines are only needed if you are using your own certificate provider.
    let rootCertificate = Data(base64Encoded: "your root certificate")
    if let rootCertificate = rootCertificate {
        networkOptions.certificates = [rootCertificate]
    }
    
    options.networkOptions = networkOptions
    MParticle.sharedInstance().start(with: options)

Was this page helpful?