Code Monkey home page Code Monkey logo

vue2-mailchimp-subscribe-component's Introduction

Vue 2 Mailchimp Subscribe Component

Vue.js 2 component for ajax subscription to Mailchimp. Because of CORS limitations, it is hardly possible to do direct queries to Mailchimp API from Javascript in browser. It is not secure either, because you would show visitors your private API key.

This component goes around the limitations by doing a JSONP request to Mailchimp endpoint that normally handles Mailchimp-generated embed forms. As far as I know, this is the only way to do a pure front-end JS subscribe without requiring any back-end scripts on the server (like PHP to get users data and then do the call itself using Guzzle or cURL).

Usage

  1. Set up your Vue.js instance and register the component as you would normally do

    import Vue from 'vue';
    import Mailchimp from './js/components/Mailchimp.vue';
    
    new Vue({
      el: '#app',
      components: { Mailchimp },
    });
    
  2. Grab form post URL and validation code from Mailchimp:

  3. Call the component in your template, passing the two copied strings from step 2 in action and validation attributes. Eg.

<mailchimp
	action="https://myaccount.us16.list-manage.com/subscribe/post?u=d993985c3acd21b37a3d9fef4&id=2645adecd7"
	validation="b_d992865c3acd21b37a3d9fef4_8515adecd7"
></mailchimp>

Demo

The component was created for the Whale Ride project, so you can see it at the bottom of the page (unless it has already been replaced). If you used it for your project, I am happy to post the link here.

Notes / To Do

  • The AJAX request is done using jQuery. I tried using AXIOS, but it didn't work very well, obviously they don't support JSONP, which is required in this case.
  • There are some JSONP adapters for AXIOS here and here, but I haven't got that far as testing them

vue2-mailchimp-subscribe-component's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.