Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wlrp__conversion-tracker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wlrp__conversion-tracker

WLRP Conversion tracking library based on Google Tag Manager

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Conversion Tracking

Initialization

<script src="path/to/conversion.js"></script>
<script>
// Minimal setup
var config = {
		id: 'GTM-123456'
	},
	reporter = new ConversionReporter(config);
</script>

This will inject the GTM script with the ID provided and initialize the Reporter object.

Setting values

// Set manually
reporter.setAmount(10);
reporter.setQuantity(2);

// Or bind to an element that has a `value` property (i.e. input)
reporter.bindAmount(document.getElementById('amountInput'));
reporter.bindQuantity(document.getElementById('quantityInput'));

This will populate the amount and quantity fields of your Reporter object. Reports can now be sent using these values. Add a custom revenue calculator to the config if you want anything more complex.

Sending the conversion

reporter.sendReport();

Conditional tracking

If you need to disable conversion tracking on a per-case basis, you can pass a boolean to the Reporter config's noTrack property. This must be a function returning a boolean value.

function minAmount() {
	// Don't track sales under a certain amount?
	return this.amount < 100;
}

var config = {
		id: 'GTM-123456'
		noTrack: minAmount
	},
	reporter = new ConversionReporter(config);

Default condition:

By default, the reporter will ignore all events if the notrack=1 param is present in the current URL.

function() {
	return window.location.search.indexOf('notrack=1') !== -1;
}

Custom calculator

To use a custom calculator for your revenue reporting, pass a function to the Reporter object's constructor that does the calculations. The function can access the quantity and amount fields of the reporter through the this interface, and must return an integer.

function calculateCustom() {
	// Only 20% commission from partner sales?
	return (this.quantity*this.amount)*0.2;
}

var config = {
		id: 'GTM-123456'
		calculator: calculateCustom
	},
	reporter = new ConversionReporter(config);

Default calculator:

function() {
	return this.quantity * this.amount;
}

Keywords

FAQs

Package last updated on 15 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc