Skip to content

Commit

Permalink
Add enumerate feature to convert operator (#116)
Browse files Browse the repository at this point in the history
* add enumerate flag to convert operator

* add version updates

* fix typo
  • Loading branch information
van-fs authored Feb 17, 2021
1 parent f9a8e90 commit edfd3a2
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 93 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Data Layer Observer follows semantic versioning when releasing updates.

## History

### 1.6.0

- `enumerate` option added to `convert` operator
- Tealium sample updated to use `enumerate` option
- Added `order_` property selector to Tealium sample

### 1.5.2

- Check if `push` and `unshift` exist in older browsers
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Sensitive, private, and confidential information should never be added to a data

DLO is a JavaScript asset that is included on a web page. FullStory hosts versions of DLO on our CDN. Versioned releases have the naming convention `<version>.js`, and the most recent version is named `latest.js`:

- https://edge.fullstory.com/datalayer/v1/1.5.2.js
- https://edge.fullstory.com/datalayer/v1/1.6.0.js
- https://edge.fullstory.com/datalayer/v1/latest.js

If you would like the most up to date version of DLO on your site always, use `latest.js`. If you'd rather use stable releases and perform manual upgrades, use `<version>.js`.
Expand Down
67 changes: 60 additions & 7 deletions docs/operator_convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Convert is most useful when paired with `FS.event` for cart and checkout events

## Options

Options with an asterisk are required.
Options with an asterisk are required. Note that `enumerate` can be used by itself or with `properties`.

| Option | Type | Default | Description |
| ------ | ---- | ------- | ----------- |
| `enumerate`* | `boolean` | `false` | Automatically converts all string values into their numeric equivalent. |
| `force` | `boolean` | `false` | If the property is undefined or has value `null`, forcibly add the property with value `0`, `0.0`,`false` or empty string. |
| `index` | `number` | `0` | Position of the object to convert in the operator input list. |
| `preserveArray` | `boolean` | `false` | If the conversion value is a list, keep the array type even if the array has a single value. |
Expand All @@ -27,8 +28,11 @@ Options with an asterisk are required.
```javascript
{
source: 'digitalData.cart.price',
operators: [ { name: 'convert', properties: 'basePrice,taxRate,shipping,priceWithTax,cartTotal', type: 'real' } ],
destination: 'FS.identify'
operators: [
{ name: 'convert', properties: 'basePrice,taxRate,shipping,priceWithTax,cartTotal', type: 'real' },
{ name: 'insert', value: 'Product Viewed' },
],
destination: 'FS.event'
}
```

Expand All @@ -54,6 +58,7 @@ Options with an asterisk are required.

```javascript
[
'Product Viewed',
{
basePrice: 15.55,
voucherCode: '',
Expand All @@ -68,15 +73,18 @@ Options with an asterisk are required.
]
```

## Converting all cart prices
## Automatically convert all "numeric" strings

### Rule

```javascript
{
source: 'digitalData.cart.price[(basePrice,cartTotal,priceWithTax)]',
operators: [ { name: 'convert', properties: '*', type: 'real' } ],
destination: 'FS.identify'
source: 'digitalData.cart.price[(available,basePrice,cartTotal,priceWithTax)]',
operators: [
{ name: 'convert', enumerate: true },
{ name: 'insert', value: 'Product Viewed' },
],
destination: 'FS.event'
}
```

Expand All @@ -85,6 +93,7 @@ Options with an asterisk are required.
```javascript
[
{
available: 'false',
basePrice: '15.55',
priceWithTax: '16.95',
cartTotal: '21.95',
Expand All @@ -96,7 +105,51 @@ Options with an asterisk are required.

```javascript
[
'Product Viewed',
{
available: 'false',
basePrice: 15.55,
priceWithTax: 16.95,
cartTotal: 21.95,
}
]
```

## Convert "numeric" strings with specific property conversions

### Rule

```javascript
{
source: 'digitalData.cart.price[(basePrice,cartTotal,priceWithTax,available)]',
operators: [
{ name: 'convert', enumerate: true, properties: 'available', type: 'bool' },
{ name: 'insert', value: 'Product Viewed' },
],
destination: 'FS.event'
}
```

### Input

```javascript
[
{
available: 'false',
basePrice: '15.55',
priceWithTax: '16.95',
cartTotal: '21.95',
}
]
```

### Output

```javascript
[
'Product Viewed',
{
available: false,
basePrice: 15.55,
priceWithTax: 16.95,
cartTotal: 21.95,
Expand Down
10 changes: 2 additions & 8 deletions examples/rules/tealium-fullstory.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"id": "fs-tealium-event",
"description": "Send Tealium data (except for customer personal details) for FS.event. See https://community.tealiumiq.com/t5/Data-Layer/Data-Layer-Definition-Retail/ta-p/17227.",
"source": "utag.data[^(brand_,browse_,cart_,category_,customer_,language_,page_,product_,search_,site_,tealium_event)]",
"source": "utag.data[^(brand_,browse_,cart_,category_,customer_,language_,order_,page_,product_,search_,site_,tealium_event)]",
"operators": [
{
"name": "query",
Expand All @@ -15,13 +15,7 @@
},
{
"name": "convert",
"properties": "cart_product_quantity,cart_total_items,product_quantity,search_results",
"type": "int"
},
{
"name": "convert",
"properties": "cart_product_price,cart_total_value,order_discount_amount,order_merchandise_total,order_shipping_amount,order_subtotal,order_tax_amount,order_total,product_discount_amount,product_original_price,product_price",
"type": "real"
"enumerate": true
},
{
"name": "insert",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fullstory/data-layer-observer",
"version": "1.5.2",
"version": "1.6.0",
"description": "Monitor, transform, and send data layer content to FullStory",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Loading

0 comments on commit edfd3a2

Please sign in to comment.