Skip to content

Commit c5efe7b

Browse files
committed
Add ProductClick EE component
1 parent 90f36e5 commit c5efe7b

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

packages/enhanced-ecommerce/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin3s-react-analytics-enhanced-ecommerce",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"author": "LIN3S",
55
"license": "MIT",
66
"description": "React components to help integrating Google Analytics and Google Tag Manager in a React application",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, {PureComponent} from 'react';
2+
import {pushDataLayer} from 'lin3s-react-analytics';
3+
import PropTypes from 'prop-types';
4+
5+
class ProductClick extends PureComponent {
6+
constructor(props) {
7+
super(props);
8+
9+
this.handleProductClick = this.handleProductClick.bind(this);
10+
}
11+
12+
handleProductClick() {
13+
const {productTransform, product, ...rest} = this.props;
14+
15+
pushDataLayer(productTransform(product, {...rest}));
16+
}
17+
18+
render() {
19+
const {component: Component, ...rest} = this.props;
20+
21+
return (
22+
<div onClick={this.handleProductClick}><Component {...rest}/></div>
23+
);
24+
}
25+
}
26+
27+
ProductClick.propTypes = {
28+
component: PropTypes.func.isRequired,
29+
product: PropTypes.object.isRequired,
30+
productTransform: PropTypes.func.isRequired,
31+
};
32+
33+
export default ProductClick;

packages/enhanced-ecommerce/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Checkout from './Checkout';
22
import Page from './Page';
3+
import ProductClick from './ProductClick';
34
import ProductDetail from './ProductDetail';
45
import ProductImpressions from './ProductImpressions';
56
import Purchase from './Purchase';
67

78
export {
89
Checkout,
910
Page,
11+
ProductClick,
1012
ProductDetail,
1113
ProductImpressions,
1214
Purchase,

0 commit comments

Comments
 (0)