Native Ads

Extracting the article id

Every publisher account has an origin and a landing page base path. These are configured under account settings in Advisible Console. If the origin is https://www.example.com and the base path is sponsored/, then the landing page URL is https://www.example.com/sponsored/articleId, where articleId is the unique id of the article.

The above example uses a dynamic route, meaning that the server will respond to everything under https://www.example.com/sponsored/. This is the recommended approach whenever possible. However, a fixed path can be used instead if dynamic routing is not a viable option.

When the landing page is loaded, the article id must be extracted from the URL. This table shows three different approaches:

RoutingBase pathExtraction command
Dynamic pathsponsored/window.location.pathname.split('/')[2]
Fixed path using searchsponsored?id=new URLSearchParams(window.location.search).get('id')
Fixed path using hashsponsored#window.location.hash.slice(1)