How to add variables / custom data to custom scripts

This article is intended for at least intermediate JavaScript developers

TLDR.

WP Full Picture stores most of trackable information in fpdata JS variable which works similarly to datalayer. Check its contents in browser’s console.

Detailed information

You can easily use in your custom scripts full range of information – from simple, like page titles or post categories through clicked elements and submitted forms, and ending on visitor country or information from other plugins and the database.

This is how it works.

WP Full Picture stores most of the tracked information in fpdata object in JavaScript. This object works similarly to datalayer in Google Tag Manager and contains all sorts of trackable information – even about e-commerce events (but they require special setup to track. More on this in a separate documentation article – in the making).

This data can be accessed in your scripts by simply referring to fpdata.variable_name.

Please enter “fpdata” in your browser’s console to see what data is available and how it changes depending on what you do on site.

Data types

There are 3 types of data that you can track – static, dynamic and e-commerce.

  1. Static data never changes. This can be a page title or a category.
  2. The dynamic data changes all the time. It can be a scroll depth, last clicked element or user’s activity time on page.
  3. E-commerce data is very specific and requires a separate article (writing in progress).

Since dynamic data changes all the time WP Full Picture uses its own custom events to make sure that the data you see in fpdata is up to date.