Skip to content
OnCharge.io
View as Markdown
Developer docs

Advertising

OnCharge Advertising runs your Google and TikTok ads and sets up Meta tracking and your Meta catalog ($99 per month plus 10% of the ad spend on campaigns OnCharge runs; campaigns you run yourself, including all Meta campaigns, carry no fee). It is a separate service from payment processing: choose it at Get Started in the merchant portal. This page covers what your store needs for it: the tracking tag, attribution for custom storefronts, the product catalog API, the WooCommerce setup and how OnCharge runs your TikTok ads.

The tracking tag#

One tag sends your storefront's events to Google, Meta and TikTok through OnCharge, with the IDs set up in the portal under Advertising → Tracking. Put it in the <head> of every page:

Every page
<script async src="https://app.oncharge.io/js/v1/growth.js" data-store="YOUR_STORE_ID"></script>

YOUR_STORE_ID is the store's ID (a UUID) from the portal's Stores page. The tag needs no API key and must never be given one.

Events#

Queue events before the tag has loaded, or call it directly once it has:

Product page
<script>
  window.ocg = window.ocg || [];
  ocg.push(['track', 'view_item', {
    value: 49.0,
    currency: 'USD',
    items: [{ id: '205', name: 'Linen shirt - Blue, M', price: 49.0, quantity: 1 }]
  }]);
</script>
After the tag has loaded
window.OnChargeGrowth.track('add_to_cart', {
  value: 98.0,
  currency: 'USD',
  items: [{ id: '205', name: 'Linen shirt - Blue, M', price: 49.0, quantity: 2 }],
});
EventWhenParameters
page_viewEach page view (in a single-page app, each route change)
view_itemA product pagevalue, currency, items
add_to_cartA product added to the cartvalue, currency, items
begin_checkoutThe checkout pagevalue, currency, items
purchaseThe order confirmation page, once per orderevent_id, transaction_id, value, currency, items
ParameterTypeNotes
event_idstringOptional; lets ad platforms drop duplicates. For purchase, use the OnCharge checkout session_id of the order: OnCharge also reports the purchase from its servers with that ID, so it is counted once.
valuenumberIn major units (49.0, not 4900).
currencystringISO 4217, e.g. USD.
transaction_idstringYour order number.
items[]array{ id, name?, price?, quantity }. Use the same id as in your catalog.

The tag applies Consent Mode v2 with the consent setting chosen in the portal. If your site has its own consent banner, pass the visitor's choices to the tag whenever they change:

From your consent banner
window.OnChargeGrowth.consent({
  ad_storage: 'granted',
  analytics_storage: 'granted',
  ad_user_data: 'granted',
  ad_personalization: 'denied',
});

Each signal is 'granted' or 'denied'. The WooCommerce plugin does this for you with any consent plugin that supports the WP Consent API.

Attribution for custom storefronts#

When a shopper arrives from an ad, the tag stores the click and browser IDs in a first-party cookie, _oc_attr (path /): base64url-encoded JSON. When your server creates the checkout session, send that object as metadata.attribution, so OnCharge can report the purchase to the ad platform the shopper came from. The values are only forwarded to the platform they belong to and are never used for the payment.

FieldSource
gclid, gbraid, wbraidGoogle Ads click
ga_client_id, ga_session_idGoogle Analytics (_ga, _ga_<id> cookies)
fbclid, fbp, fbcMeta click and browser IDs (_fbp, _fbc cookies)
ttclid, ttpTikTok click and browser IDs (_ttp cookie)
landing_urlFirst page of the visit
user_agentThe shopper's browser
consent{ ad_storage, analytics_storage, ad_user_data, ad_personalization }, each granted or denied

Treat the cookie as untrusted input: keep only these fields, drop values that are not strings or are too long (2 KB for landing_url, 512 characters otherwise), and never cut a click ID short.

attribution.mjs (Node)
const FIELDS = ['gclid', 'gbraid', 'wbraid', 'ga_client_id', 'ga_session_id', 'fbclid', 'fbp', 'fbc', 'ttclid', 'ttp', 'landing_url', 'user_agent'];
const CONSENT = ['ad_storage', 'analytics_storage', 'ad_user_data', 'ad_personalization'];

/** metadata.attribution from the _oc_attr cookie value, or undefined. */
export function attributionFromCookie(raw, userAgent) {
  let data = {};
  try {
    if (raw && raw.length <= 4096) data = JSON.parse(Buffer.from(raw, 'base64url').toString('utf8'));
  } catch {
    data = {};
  }
  const out = {};
  for (const field of FIELDS) {
    const value = data?.[field];
    const max = field === 'landing_url' ? 2048 : 512;
    if (typeof value === 'string' && value.length > 0 && value.length <= max) out[field] = value;
  }
  if (!out.user_agent && userAgent) out.user_agent = String(userAgent).slice(0, 512);
  const consent = {};
  for (const key of CONSENT) if (['granted', 'denied'].includes(data?.consent?.[key])) consent[key] = data.consent[key];
  if (Object.keys(consent).length) out.consent = consent;
  return Object.keys(out).some((k) => k !== 'user_agent') ? out : undefined;
}

// When creating the session:
// body.metadata = { ...body.metadata, attribution: attributionFromCookie(req.cookies._oc_attr, req.headers['user-agent']) };

Product catalog API#

Shopping ads need your products in Google Merchant Center and the Meta catalog. Send them to OnCharge and it keeps both up to date. Requests are signed like every other API call (see Authentication & signing); full field lists are in the API reference.

HTTP
POST /api/v1/catalog/products/batch
Request
{
  "items": [
    {
      "id": "205",
      "item_group_id": "200",
      "title": "Linen shirt - Blue, M",
      "description": "Soft linen shirt.",
      "link": "https://shop.example.com/product/linen-shirt/?attribute_pa_color=blue",
      "image_link": "https://shop.example.com/wp-content/uploads/linen-shirt-blue.jpg",
      "price_minor": 4900,
      "sale_price_minor": 3900,
      "currency": "USD",
      "availability": "in_stock",
      "brand": "Acme",
      "gtin": "0012345678905",
      "product_type": "Apparel > Shirts",
      "attributes": { "Color": "Blue", "Size": "M" }
    },
    { "id": "310", "title": "Lab vial", "link": "https://shop.example.com/product/vial/", "price_minor": 8000, "currency": "USD", "ruo": true }
  ],
  "deletes": ["198"]
}
Response
{
  "results": [
    { "id": "205", "status": "created", "advertisable": true, "ruo": false, "excluded_reason": null },
    { "id": "310", "status": "created", "advertisable": false, "ruo": true, "excluded_reason": "missing_image" },
    { "id": "198", "status": "deleted" }
  ],
  "counts": { "created": 2, "updated": 0, "unchanged": 0, "deleted": 1, "not_found": 0, "rejected": 0 }
}
  • Up to 500 products and deletes per request, each id once (at most 50 characters). Prices are in minor units, as shown in your store.
  • Send a variant per row with item_group_id set to the parent; don't send the parent itself.
  • A product sent again is updated; an identical one is not rewritten (unchanged). A delete takes the product off the ad platforms.
  • Titles are cut to 150 characters and descriptions to 5,000; HTML is removed; a GTIN is kept only when it is 8–14 digits.

What OnCharge sends, and what it keeps back#

Every product is sent to the ad platforms, and each platform reviews it against its own policies. A disapproval comes back with the platform's reason and shows on the portal's Advertising → Catalog page. ruo: true is a label only: an RUO product is sent like any other.

OnCharge keeps a product back (stored, and listed on the Catalog page with the reason, but not sent) only for one of these excluded_reason values:

ResultWhy
merchant_excludedYou sent excluded: true.
controlled_substanceThe product names a controlled substance (U.S. DEA schedules I to V). Controlled substances are never sent to an ad platform or advertised.
insecure_linkThe link is not https://. A new product with an http link is rejected; one already stored is excluded.
missing_imageNo image_link.
zero_priceprice_minor is 0.

Keeping the catalog in sync#

  1. Send changed products as they change (batch them, for example every minute).
  2. Once a day, send everything.
  3. Then page through GET /api/v1/catalog/products?limit=500&offset=… (sign an empty body; the query string is not signed) and delete IDs you no longer sell.

The WooCommerce plugin does all three for you.

WooCommerce#

The OnCharge Secure Checkout plugin (1.5.0 or later) includes everything above. In WordPress, go to WooCommerce → Settings → Integration → OnCharge Marketing. It uses the Store ID, API Key and API Secret you entered in the payment settings (see WooCommerce).

SettingWhat it does
Tracking tagAdds the tag and sends view_item, add_to_cart (classic, AJAX and Blocks), begin_checkout and purchase (once per order, with the OnCharge session ID as event_id). Checkout sessions carry metadata.attribution.
Cookie consentPasses visitors' choices from a WP Consent API consent plugin to the tag.
Product syncSends published products and variations; changes within a minute, everything daily, and removes products you deleted.
Categories to excludeProducts in these categories are never advertised.
RUO categoriesProducts in these categories are labelled RUO in your OnCharge catalog. The label is information only: they are sent to the ad platforms like any other product, and the tag loads on their pages.

The settings page shows the last sync, counts, errors and products OnCharge rejected, with a Sync all products now button. On your home page the plugin also adds the Google site-verification tag OnCharge needs to verify your site in Merchant Center.

TikTok#

OnCharge runs your TikTok ads from its own TikTok Business Center, as your agency: in TikTok it appears as your partner, OnCharge Group LLC. Set it up in the portal under Advertising → TikTok.

Your TikTok ad account#

Use my TikTok ad accountCreate one for me
OwnerYouYour business, under OnCharge's Business Center
Who pays TikTokYou, with your TikTok payment methodOnCharge, from your prepaid advertising balance (spend at cost plus the 10% management fee)
SetupShare the account with OnCharge as a partnerOne click, once Advertising is active and billing is set up

Use my TikTok ad account. In TikTok Business Center go to Business settings → Users → Partners → Add partner, enter OnCharge's Business Center ID 7707361902699298817, choose Ad accounts, select the store's ad account and give it the Operator permission. Then enter the ad account ID on the TikTok page and choose Check connection.

Create one for me. OnCharge creates the ad account with the business details from your OnCharge application: your registered business name, website, country and contact details. They cannot be typed in at this step; contact support if they are wrong. OnCharge keeps about three days of your approved budget in the account, never more than your advertising balance covers. If your balance cannot cover more spend, OnCharge pauses the campaigns and moves the unused money back. OnCharge creates TikTok ad accounts for stores in the RUO programme too; TikTok reviews each account and its ads against its own policies.

Campaigns#

OnCharge Ads AI writes a TikTok Smart+ plan for your store: a campaign name, a daily budget, the countries, three to five ad texts, the button (for example Shop now) and a short brief for the video. TikTok's Smart+ then chooses the audience (adults only), bids and placements. Nothing launches until you, or OnCharge on your behalf, approve the plan.

RuleLimit
BudgetAt least $20 a day (TikTok's minimum), so at least $600 a month
Ad text12–100 characters each, up to 5; no emoji, web addresses or phone numbers
Landing pageAn https:// page of your own store
VideoMP4, MOV or MPEG, up to 500 MB; vertical 9:16, 9–30 seconds works best
Brand profile (video ads)Your own brand name, 2–40 characters; square PNG or JPEG logo, 100 pixels or more, up to 500 KB

Before you approve, add the creative: upload a video, or use one of your TikTok posts with its Spark Ads authorization code (in the TikTok app open the post, then Ad settings → Ad authorization, and generate a code). Video ads appear on TikTok under your brand: on the TikTok page save a display name (your store's own brand name, 2–40 characters) and a square PNG or JPEG logo (at least 100 pixels wide, up to 500 KB). OnCharge sets up this profile in your ad account once and uses it for every video ad; until it is saved, approved video campaigns wait. Ads made from a Spark Ads post appear under that post's TikTok account instead. Your store's TikTok pixel must be in the ad account so Smart+ can optimise for purchases; for an account OnCharge creates, OnCharge adds a pixel when your store has none.

Approving needs an advertising balance that covers three days of the plan's management fee, and of its spend when OnCharge pays TikTok. OnCharge then builds the campaign switched off, adds its ad group and ad, and switches it on.

TikTok Autopilot#

Autopilot runs TikTok for you from Advertising → TikTok Autopilot.

  1. Connect TikTok. Sign in to TikTok once. OnCharge adds its Business Center as a partner with Admin access to the ad account you pick, and makes sure the account has a pixel for your store. If the ad account is not in a Business Center you manage, TikTok does not allow this step to be done for you: the page shows the three clicks to do it by hand, or OnCharge can create an ad account for you.
  2. Brand kit. OnCharge reads your website for your name, logo, colours and product pictures, and each product's search title and description. Correct anything and upload your own pictures and videos (PNG, JPEG, MP4 or MOV). List what your ads must never say; every video is checked against it.
  3. Research. OnCharge finds your competitors, the ads they keep running on Google (from the Ads Transparency Center, with how long each has run) and how your products are worded in search results, and OnCharge Ads AI turns that into angles and opening lines. TikTok and Meta do not publish an ad library for ordinary ads in the United States, so competitor ads come from Google's.
  4. Videos. OnCharge Creative Studio makes vertical 10–15 second videos, each on a different angle, starting from your own product picture where there is one. A concept is set aside before any video is made if it makes a medical or health claim, promises a result, describes use on or in the body, addresses a viewer's personal attributes, breaks your own list, or names a controlled substance.
  5. Testing. Each approved video runs as its own ad with its own daily budget ($25 by default; TikTok's minimum is $20). After about twice your target cost per sale without a sale, an ad is stopped. An ad that sells under the target for two days gets more budget, one step a day (20% by default). New videos lean towards the angles that have sold for your store.
ModeNew ad goes liveLosing ad is stoppedWinner's budget is raised
Manual ReviewYou approveYou approveYou approve
Semi AutoYou approveAutomaticYou approve
Full AutopilotAutomaticAutomaticAutomatic

Your limits apply in every mode: a daily limit for all ads together, the most one ad may reach, how many ads run at a time and how fast a budget may grow. Choosing Full Autopilot asks you to agree to those limits, and raising one later asks again. Nothing is raised or launched that your advertising balance does not cover. Every decision is listed with the numbers behind it, and you can pause Autopilot or any single ad at any time.

Changes and results#

From the TikTok page you can pause a campaign or everything, switch them back on, change a daily budget or replace the ad text. OnCharge applies each change in TikTok within minutes. Outside Full Autopilot (below), nothing that raises spend happens automatically: when your balance runs out OnCharge pauses every campaign in the account, and after you add funds you approve restarting them. Spend, purchases and purchase value appear on the TikTok page, updated every few hours.