# wp-parsely/3.0.0/src/js/lib/init-api/index.js

Parse.ly, version 3.0.0. 38 lines.

- Page: https://pluginprobe.com/plugins/wp-parsely/3.0.0/code/src/js/lib/init-api/index.js
- Raw: https://pluginprobe.com/plugins/wp-parsely/3.0.0/raw/src/js/lib/init-api/index.js
- Modified: 2021-08-11T02:28:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-parsely/3.0.0/code/src/js/lib/init-api/index.js#L10-L20`.

```javascript
async function uuidProfileCall() {
	const apikey = global.wpParsely?.apikey;
	const uuid = global.PARSELY?.config?.parsely_site_uuid;

	if ( ! ( apikey && uuid ) ) {
		return;
	}

	const url = `https://api.parsely.com/v2/profile?apikey=${ encodeURIComponent(
		apikey
	) }&uuid=${ encodeURIComponent( uuid ) }&url=${ encodeURIComponent( window.location.href ) }`;

	return fetch( url );
}

export function initApi() {
	if ( typeof global.PARSELY === 'object' ) {
		if ( typeof global.PARSELY.onload !== 'function' ) {
			global.PARSELY.onload = uuidProfileCall;
			return;
		}
		const oldonload = global.PARSELY.onload;
		global.PARSELY.onload = function() {
			if ( oldonload ) {
				oldonload();
			}
			uuidProfileCall();
		};
		return;
	}

	global.PARSELY = {
		onload: uuidProfileCall,
	};
}

initApi();

```
