SLP Helper
This library will enable you to develop Smart LemonPI Pixels faster and more compact, by providing and supporting the most used scraper functionalities through
window.slp
.
Basic example (ES6)
windowslp;
Advanced example (ES6)
windowslp;
config
)
Configuration (You can configure the way the SLP Helper will behave through the config
object.
-
testUrl
(RegEx
) Pass a regular expression to test againslocation.href
. The SLP Helper won't scrape on fail. -
optionalFields
(Array
) Pass an array of field names (strings) that may scrape empty or undefined. (Only applies to optional fields, see below) -
watchChanges
(Boolean
, default:false
) Set to true to expect value changes (multiple scrapes) throughout a single page visit. User input and/or asynchronous calls are the most common causes. (Will enforcetrue
whenlongestViewed
is set) -
longestViewed
(Boolean
, default:false
) Set to true to simulate a non-existing LemonPI business rule Longest viewed by user. This functionality is achieved by scraping every second a user is active on the page. This only works when used in conjunction with the Most viewed by user business rule in LemonPI Manage. -
interval
(Integer
, default:500
) The amount of milliseconds of delay between value checks. (Will enforce5000
whenlongestViewed
istrue
) -
debug
(Boolean
, default:false
) Set to true to enforce console debugging. Not recommended, add lemonpi_debug somewhere in the query string instead. -
beforePush
(Function
) Optional lifecycle hook to (asynchronously) alter the result object, before pushing it to LemonPI. Takes inresult
(Object
) anddone
(Function
) as arguments.
Public methods
-
window.slp.getUrl([Object])
Will return the current URL without query parameters and hash, and accepts optional configuration. See examples above for usage. -
window.slp.getUrlPathSegment(Integer)
Use this method to get a specific URL path segment (String). See examples above for usage. -
window.slp.getUrlPathSegments()
Use this method to get all URL path segments (Array). -
window.slp.getUrlQueryParameter(String)
This method will let you grab the value of a specific URL query parameter (String). See examples above for usage. -
window.slp.getUrlQueryParameters()
This method will let you grab all URL query parameters (Object). -
window.slp.generateHash(String|Number|Array|Boolean|Object[, ...[, ...]])
Will return a unique string ([0-9-]
) based on all JSON-friendly arguments passed. -
window.slp.getBackgroundImageUrl(String)
Returns the computed background image URL of a supplied element, or element selector. -
window.slp.setCookie(String, String|Number|Array|Boolean|Object)
Set a cookie (key, value). Values will be JSON stringified. -
window.slp.getCookie(String)
Get a cookie value by its key. Values will be JSON parsed. -
window.slp.scrape(Object)
Will performwindow.lemonpi.push()
when the output is considered valid.
LemonPI field defaults and value types
Required
title
(String
)imageUrl
(String
)advertiserId
(Integer
)dynamicInputId
(Integer
)
Default values
id
(String
, default:"91374653451044"
[unique hash based on all field values] [values will be converted to[a-z0-9-]
])category
(String
, default:"none"
[values will be converted to[a-z0-9-]
])clickUrl
(String
, default:"https://..."
[current URL without parameters or hash])available
(Boolean
, default:true
)type
(String
, default:"propSeen"
, other allowed values:"propInBasket"
,"propPurchased"
)
Optional
description
(String
)logoUrl
(String
)expiresOn
(String
)priceNormal
(String
)priceDiscount
(String
)stickerText
(String
)custom1
(String
)custom2
(String
)custom3
(String
)custom4
(String
)