Giter VIP home page Giter VIP logo

customeriosharp's Introduction

Customer.io API C# implementation

Implementation of Customer.io's write-only API for .NET.

Installation

Using Nuget:

Install-Package CustomerIOSharp

Usage

We recommend you implement the ICustomerFactory interface yourself. Here is a suggested implementation used in one of my projects:

    public class CustomerFactory : ICustomerFactory
    {
        public ICustomerDetails GetCustomerDetails()
        {
            var user = MembershipHelper.GetCurrentUser();
            return user == null 
                ? null 
                : user.AsCustomer();
        }

        public string GetCustomerId()
        {
            var user = MembershipHelper.GetCurrentUser();
            return user == null
                ? null
                : user.UserId.ToString();
        }
    }

Then instantiate CustomerIo and call IdentifyAsync():

var customerIo = new CustomerIo(
    "siteid", 
    "apikey", 
    new CustomerFactory());
await customerIo.IdentifyAsync();

You should most likely only call IdentifyAsync() whenever the user logs in or is changed.

If you do not want to implement ICustomerFactory, you can simply provide the required details to each call:

await customerIo.IdentifyAsync(User.AsCustomer());

Whatever you do, you will have to provide customer data implementing ICustomerDetails. It has only two required properties, but any properties you supply in your implementation will be forwarded to customer.io:

public class Customer : ICustomerDetails 
{
    // these two fields are required:
    public string Id { get; set; }
    public string Email { get; set; }
    // these are my custom fields:
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Custom events

Track a custom event by calling TrackEvent(). It takes an event name as the first parameter, the second parameter is any serializable object. Note that it automatically posts using the correct customer (using ICustomerFactory), but you can also supply your own.

await customerIo.TrackEventAsync("signup", new {
	UserGroup = "trial",
	Referrer = "email campaign"
});

// this event has no data and uses a different customer
await customerIo.TrackEventAsync("signup", customerId: "foo");

Note that these two variables will be camelcased before being sent to customer.io, so userGroup and referrer will be available in your transactional campaigns.

License

Dual licensed under the MIT and the GPL license.

You don’t have to do anything special to choose one license or the other and you don’t have to notify anyone which license you are using.

MIT license

The MIT License (MIT)

Copyright (c) 2013-2017 Digital Creations AS.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

GPL license

Copyright (c) 2013-2017 Digital Creations AS.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

customeriosharp's People

Contributors

vegardlarsen avatar francisrath avatar zimmpatrick avatar saxondruce avatar southcentralcode avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.