Targeting by IP Address

Due to the way our API and Javascript SDK communicate, targeting users by their IP address is not enabled by default.  We do, however, provide an API endpoint that can be used to introduce IP as a User Property.

This setup requires a slightly customized `Appcues` (or `analytics`, if using Segment) `identify` call, as illustrated in the examples below.  To enable it, simply follow the example that best fits your app.

API Endpoint

The following endpoint will return the requestor's IP address, which can then be passed to Appcues as a User Property...

https://api.appcues.net/v1/remote_ip

Examples

The following examples are provided for illustrative purposes.  The strategy you ultimately use will depend on how your app is built, but chances are one of the following will seem familiar.

Alternative 1: Use JSONP and a callback function (great for older, server-rendered sites)

<script src="//fast.appcues.com/<YOUR_APPCUES_ID>.js"></script>
<script>
    function appcuesIdentifyWithIP(json) {
        Appcues.identify('<USER_ID>', {
            ip: json.remote_ip,
            email: 'user@email.com',
            name: 'user name',
            addtlProp0: 'addtlProp0'
        });
    }
</script>
<script type="application/javascript" src="https://api.appcues.net/v1/remote_ip?callback=appcuesIdentifyWithIP"></script>

Alternative 2: Use jQuery (the easiest option, if you're including it already)

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="//fast.appcues.com/<YOUR_APPCUES_ID>.js"></script>
<script>
    $.getJSON("https://api.appcues.net/v1/remote_ip", function(json) {
        Appcues.identify('<USER_ID>', {
            ip: json.remote_ip,
            email: 'user@email.com',
            name: 'user name',
            addtlProp0: 'addtlProp0'
        });
    });
</script>

Alternative 3: Use the new Fetch API (best for ES6 codebases packaged with Webpack/similar)

<script src="//fast.appcues.com/<YOUR_APPCUES_ID>.js"></script>
<script>
    fetch("https://api.appcues.net/v1/remote_ip").then(function(response) {
        return response.json();
    }).then(function(json) {
        Appcues.identify('<USER_ID>', {
            ip: json.remote_ip,
            email: 'user@email.com',
            name: 'user name',
            addtlProp0: 'addtlProp0'
        });
    });
</script>

As always, feel free to reach out for more specific guidance.

Still need help? Contact Us Contact Us