2.0.1 • Published 5 years ago

react-datalayer v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-datalayer

Greenkeeper badge

  • simple declerative api
  • no more propagate props just for dataLayer's purpose
  • separate view layer from analytics layer
  • easy to implement

before:

import React from 'react';


const ListItem = ({ id, index, name, href }) => <a href={ href } onClick={ () => dataLayer.push({ index, id, name, href }) }>{ name }</a>

const List = ({ elements }) => elements.map(({ id, name, href }, index) => {
  return (
    <ListItem { ...{name, href, index, id} }/>
  );
});

export default List;

after:

import React from 'react';

import { Tracking, provideAnalytics } from 'react-datalayer';

const ListItem = ({ onClick, name, href }) => <a href={ href } onClick={ onClick }>{ name }</a>

const List = ({ elements }) => elements
  .map(({ id, name, href }, index) => {
    return (
      <Tracking eventProperties={ () => ({ id, index, name, href }) }>
        {
          instrument => <ListItem onClick={ instrument('click') } { ...{ name, href } }/>
        }
      </Tracking>
    )
  });

export default provideAnalytics({ userId: 2 })(List);

Check out more examples and get stuck right in with the online editor.

Resources

Todos

  • useAnalytics, useTracking
  • ts interfaces
  • storybook online
  • custom dispatch definintion
  • tests
  • eslint
2.0.1

5 years ago

2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago