General Implementation of theMarketer for Other E-commerce Platforms

You don't need extensions to start using theMarketer. If your e-commerce platform is not yet supported by our platform, our General Documentation will help you get started.

Please keep in mind that in order for the integration to work properly, Google Tag Manager must be installed on your website.

1. JavaScript Tracking Code

In order for theMarketer to record the necessary events from your site, you have to insert the following JavaScript code right before the closing of < head > tag.

To use theMarketer you need the Tracking Key from your theMarketer account. The Tracking Key is automatically generated when you register your account, and you can find it in Settings -> Technical Integration.

This code is loaded asynchronously, which means it won't slow down in any way the page's load time and it will work independently from your application.

<script>
   (function(){
       mktr_key = "your_marketer_tracking_key";
       var mktr = document.createElement("script");
        mktr.async = true;
       mktr.src = "https://t.themarketer.com/t/j/" + mktr_key;
       var s = document.getElementsByTagName("script")[0];
       s.parentNode.insertBefore(mktr,s);
    })();
</script>

2. Capturing On-site events

On-site events will need to be pushed into the Google Tag Manager dataLayer in order to be tracked by theMarketer.

Set email

The __sm__set_email event needs to be called each time a guest registers, logs in or fills in the email address in a form on the website (e.g. Contact or Newsletter Form

<script> 
   dataLayer.push({
       event: "__sm__set_email",
       email_address: "john@doe.com",
       firstname: "John",
       lastname: "Doe"
   });
</script>

Set phone

The __sm__set_phone event needs to be called each time a guest registers or fills in their phone number in a form on the website.

<script>
   dataLayer.push({
       event: "__sm__set_phone",
       phone: '0700000000'
   });
</script>

View homepage

The __sm__view_homepage event needs to be called every time a user visits the homepage of your website

<script>
   dataLayer.push({
        event: "__sm__view_homepage"
   });
</script>

View category

The __sm_view_category event must be called when a visitor goes to a category page. In this case, the category page is the page that displays the category details and its list of subcategories or the page that lists the products of a certain category. The “category” parameter must include the full breadcrumb of the category.

<script>
   dataLayer.push({
       event: "__sm__view_category",
       category: "Men|Shoes|Sneakers"
   });
</script>

View brand

The __sm__view_brand event must be called every time a visitor lands on a producer/brand page. In this case, the brand page is the page where the brand details are listed, or the page that lists the products belonging to that particular brand.

<script>
   dataLayer.push({
        event: "__sm__view_brand",
        name: "Nike"
   });
</script>

View product

The __sm_view_product event must be called every time a visitor clicks on a product details page.

<script>
   dataLayer.push({
       event: "__sm__view_product",
       product_id: 4421
   });
</script>

Add to cart

The __sm__add_to_cart event must be called every time a product is added to cart.

If you redirect the user to another page (e.g. the checkout page) right after they added the product to cart, the add-to-cart function must be triggered in the callback of your add-to-cart function.

If add-to-cart is possible in other pages too, other than in the product details page, the event must be triggered in those pages as well.

Variation of a product is the product properties group the user must choose before being able to add a product to cart: color, size, capacity, etc. For example, an online fashion store can set a system based on color and size variations: "Y - 32" (yellow color and size 32), "R - XS" (red color and size XS), "M" (size M) etc.

<script>
   dataLayer.push({  
        event: "__sm__add_to_cart",
        product_id: 4421,
        quantity: 1,
        variation: {
            id: 4422,
            sku: "ABC123-S"
        }
   });
</script>

Remove from cart

The __sm_remove_from_cart event must be called every time a product is removed from cart.

<script>
   dataLayer.push({  
        event: "__sm__remove_from_cart",
        product_id: 4421,
       quantity: 1,
       variation: {
            id: 4422,
            sku: "ABC123-S"
        }
   });
</script>

Add to wishlist

The __sm__add_to_wishlist event must be called every time a product is added to the wishlist.

If you redirect the user to another page right after they added a product to the wishlist, the add-to-cart function must be triggered in the callback of your add-to-wishlist function.

If add-to-wishlist is possible in other pages too, other than in the product details page, the event must be triggered in those pages as well.

<script>
   dataLayer.push({
      event: "__sm__add_to_wishlist",
      product_id: 4421,
      variation: {
            id: 4422,
            sku: "ABC123-S"
       }
   });
</script>

Remove from wishlist

The __sm_remove_from_wishlist event must be called every time a product is removed from the wishlist.

<script>
   dataLayer.push({  
        event: "__sm__remove_from_wishlist",
       product_id: 4421,
       quantity: 1,
        variation: {
            id: 4422,
            sku: "ABC123-S"
       }
   });
</script>

Initiate checkout

The __sm__initiate_checkout event needs to be called every time a user goes to the checkout page. If your platform has the checkout process in the same page as the cart page, the function will need to be called when the user goes to the cart page.

<script>
   dataLayer.push({
       event: "__sm__initiate_checkout"
   });
</script>

Save order

The __sm__order event must be called whenever an order is successfully registered.

For any payment method, the function must be called on the Thank You page (the page where the user is informed the order was registered). If there is no Thank You page, the function must be called after the order is successfully stored in the database.

For example, for online payment method, the function must be called after the response from the payment processor is received and the answer is positive (not error or fail). In this case it means the order is successfully registered (was paid). The function must be called in the Thank You page, when all the order registration process is finalized.

<script>
   dataLayer.push({
        event: "__sm__order",
        number: 1234, //or text "XYZ1234" 
        email_address: "customer@example.com",
        phone: "0700000000",
        firstname: "John",
        lastname: "Doe",
        city: "Bucharest",
        county: "Bucharest",
        address: "Customer billing address",
        discount_value: 10, // Final value of the discount, such as 10 EUR, without currency
        discount_code: "XYZA124", //If no discount code is used by the customer, set empty string
        shipping: 10,
        tax: 20, //final value of taxes (VAT), such as 20 EUR, without currency,
        total_value: 230,
        products: [
           {
               product_id: 4421,
               price: 100,
               quantity: 1,
               variation_sku: "ABC123-S"
            },
            {
               product_id: 4425,
               price: 80,
               quantity: 1,
               variation_sku: "ABC125-M"
           }
        ]
   });
</script>

Search

The __sm__search event must be called each time the search functionality on your website is used.

<script>
   dataLayer.push({
       event: "__sm__search",
       search_term: "sneakers"
   });
</script>

Custom events

If you want to send a Custom event from your website, you will first need to create the event in theMarketer interface, in the Settings -> Technical integration section. The event name created will need to match the event which is sent from the website. Both the event and the email parameters are mandatory.

<script>
   dataLayer.push({
       event: "__sm__event_identifier",
       email: customer@email.com
       payload: "any type of custom information" 
   });
</script>

3. Product feed

In order for theMarketer to display only the products in stock, you will need to create an XML product feed.

The product feed needs to be accessible on your website (eg. https://www.yourwebsite.com/product_feed.xml)

Sample feed file:

<?xml version="1.0" encoding="UTF-8"?>
<products>
  <product>
      <id>123</id>
      <sku>ABC123</sku>
      <name><![CDATA[Sample product name]]></name>
      <description><![CDATA[Sample product description]]></description>
      <url>https://www.yourwebsite.com/sample-product-url</url>
      <main_image>https://www.yourwebsite.com/main_image.jpg</main_image>
      <category><![CDATA[Men|Clothes|Shirts]]></category> <!-- full category tree, categories separated by | -->
      <brand><![CDATA[Brand name]]></brand>
      <acquisition_price>20</acquisition_price>
      <price>85</price>
      <sale_price>39</sale_price>
      <sale_price_start_date>2022-05-02 09:00</sale_price_start_date> <!-- promo price availability start date -->
      <sale_price_end_date>2022-05-10 09:00</sale_price_end_date> <!-- promo price availability end date -->
      <availability>1</availability> <!-- 0 - out of stock, 1 - in stock, 2 - in supplier stock -->
      <stock>200</stock> <!-- Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1 -->  
     <media_gallery>
         <image>https://www.yourwebsite.com/image1.jpg</image>
         <image>https://www.yourwebsite.com/image2.jpg</image>
         <image>https://www.yourwebsite.com/image3.jpg</image>
      </media_gallery>
      <variations>
          <variation>
            <id>123</id>
            <sku>ABC123-S</sku>
            <acquisition_price>20</acquisition_price>
            <price>85</price>
            <sale_price>39</sale_price>
            <size><![CDATA[S]]></size> <!-- filled in if variation is on size, else do not send the size parameter -->
            <color><![CDATA[Red]]></color> <!-- filled in if variation is on color, else do not send the color parameter -->
            <availability>1</availability> <!-- 0 - out of stock, 1 - in stock, 2 - in supplier stock -->
            <stock>20</stock> <!-- Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1 -->
          </variation>
          <variation>
            <id>123</id>
            <sku>ABC123-M</sku>
            <acquisition_price>20</acquisition_price>
            <price>85</price>
            <sale_price>39</sale_price>
            <size><![CDATA[M]]></size> <!-- filled in if variation is on size, else do not send the size parameter -->
            <color><![CDATA[Red]]></color> <!-- filled in if variation is on color, else do not send the color parameter -->
            <availability>1</availability> <!-- 0 - out of stock, 1 - in stock, 2 - in supplier stock -->
            <stock>20</stock> <!-- Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1 -->
          </variation>
        </variations>
      <created_at>2021-04-18 08:15</created_at> <!-- when product was added to the store -->
      <extra_attributes> <!-- extra product attributes available in the platform, empty if there are no attributes -->
          <attribute_name_from_your_platform><![CDATA[Attribute value]]></attribute_name_from_your_platform>
      </extra_attributes>
  </product>
</products>

4. Categories feed

To ensure a better mapping of your product categories, you can create an XML feed with the categories in your store. The feed is optional, but recommended, and can be set up in the Settings -> Products section, under Categories Feed.

The categories feed needs to be accessible on your website (eg. https://www.yourwebsite.com/categories_feed.xml)

Sample feed file:

<?xml version="1.0" encoding="UTF-8"?>
<categories>
  <category>
    <name>Shirts</name>
    <url>https://www.yourwebsite.com/categories/shirts</url>
    <id>12</id>
    <hierarchy>Apparel|Men|Shirts</hierarchy>
   <image_url>https://www.yourwebsite.com/categories/images/shirts.jpg</image_url> <!-- minimum recommended size is 100x100px →
  </category>
  <category>
    <name>Blazers</name>
    <url>https://www.yourwebsite.com/categories/blazers-men</url>
    <id>13</id>
    <hierarchy>Apparel|Men|Blazers</hierarchy>
  </category>
  <category>
    <name>Blazers</name>
    <url>https://www.yourwebsite.com/categories/blazers-women</url>
    <id>14</id>
    <hierarchy>Apparel|Women|Blazers</hierarchy>
  </category>
  <!-- more categories -->
</categories>

5. Brands feed

To ensure a better mapping of your product brands, you can create a XML feed with the brands in your store. The feed is optional, but recommended, and can be set up in the Settings -> Products section, under Brands Feed.

The brands feed needs to be accessible on your website (eg. https://www.yourwebsite.com/brands_feed.xml)

Sample feed file:

<?xml version="1.0" encoding="UTF-8"?>
<brands>
  <brand>
    <name>NiceShirts</name>
    <url>https://www.yourwebsite.com/brands/nice-shirts</url>
    <id>10</id>
    <image_url>https://www.yourwebsite.com/images/brands/nice-shirts.png</image_url> <!--minimum recommended size is 100x100px →
  </brand>
  <brand>
    <name>Blue</name>
    <url>https://www.yourwebsite.com/brands/blue</url>
    <id>11</id>
  </brand>
</brands>

6. Orders feed for one time import

If you want to import your existing orders for the Loyalty Program and RFM Analysis, you can do so by creating a JSON order feed. Only the orders from the last 3 years will be imported.

JSON Structure:

{
	"orders": {
		"order": [{
			"order_no": "100000049",
			"order_status": "Fulfilled",
			"refund_value": "0.00",
			"created_at": "013-03-15 02:01",
			"email_address": "john.doe@domain.com",
			"phone": "0700000000",
			"firstname": "John",
			"lastname": "Doe",
			"city": "City",
			"county": "County",
			"country": "RO", //country ISO code
			"address": "Customer address",
			"discount_value": "0.00",
			"discount_code": "",
			"shipping": "20",
			"tax": "24",
			"total_value": "153.50",
			"products": [{
				"product_id": "377",
				"name": "Product name",
				"url": "https://yourwebsite.com/product-url",
				"main_image": "https://yourwebsite.com/product-image.jpg",
				"category": "Some category",
				"brand": "Brand name",
				"price": "750.00",
				"sale_price": "650.00",
				"quantity": 1,
				"variation_id": "377",
				"variation_sku": "alb007"
			}]
		}]
	}
}

7. Save Order API

In addition to the __sm_order_event, it is also recommended to make an API call to our Save Order API, to ensure that all orders placed on your website are captured properly.

The API call needs to be made after the order has been placed successfully.

Sample code:

$apiURL = "https://t.themarketer.com/api/v1/save_order";
$apiKey = "MyAPI_REST_Key";
$customerId = "CUSTOMER_ID";

$client = new Client();

$orderData = [
     "k" => $apiKey,
     "u" => $customerId,
     "number" => "3301", //or text "XYZ1234"
     "email_address" => "john.doe@email.com",
     "phone" => "0700000000",
     "firstname" => "John",
     "lastname" => "Doe",
     "city" => "Bucharest",
     "county" => "Bucharest",
     "address" => "Customer billing address",
     "discount_value" => 10, // Final value of the discount, such as 10 EUR
     "discount_code" => "XYZA124",
     "shipping" => 10,
     "tax" => 20, //final value of taxes (VAT), such as 20 EUR (not the percentage of the tax),
     "total_value" => 230,
     "products" => [
           [
            "product_id" => 1159,
            "price" => 100,
            "quantity" => 1,
            "variation_sku" => 'ABC123-S'
           ],
           [
            "product_id" => 2334,
            "price" => 100,
            "quantity" => 1,
            "variation_sku" => 'ABC123-S'
           ]
     ]
];

$request = $client->request("POST", $apiURL, ['query' => $orderData]);

8. Syncing order statuses

When order statuses are updated in your ecommerce platform, for example from Pending to Processing or from Processing to Fulfilled, an API call will need to be made to our Order status API, in order to update the order’s status in theMarketer as well.

Sample code:

<?php
$apiURL = "https://t.themarketer.com/api/v1/update_order_status";
$apiKey = "MyAPI_REST_Key";
$userId = “Customer_id_from_theMarketer”;

$client = new GuzzleHttp\Client();

$orderStatus = [
  "k" => $apiKey,
   “order_number” => 1234, //or text “XYZ1234”,
   “u” => $userId,
   “order_status” => Fulfilled //use the specific statuses of the e-commerce platform, mapping will be done by us
];

$registerRequest = $client->request("GET", $apiURL, ["query" => $orderStatus, "timeout" => 2]);
?>

9. Discount codes API

If you want to use unique discount codes for your customers inside theMarketer platform, for Automation or Loyalty Program purposes, for example, you will need to create an endpoint in your ecommerce platform, which supports the generation of discount codes.

theMarketer currently supports 3 discount types: Fixed, Percentage and Free Shipping.

Optionally, discount rules in theMarketer platform can also have an expiration date. If the call we make to your API features an expiration date, it will need to be taken into account when creating the discount code.

<?php

 $restApiKey = 'REST_KEY_FROM_THEMARKETER';  \\ you will need to replace this with yout own REST API KEY
 
 if (isset($_GET['key']) && $_GET['key'] === $restApiKey && gettype($_GET['value']) === 'integer' && gettype($_GET['type']) === 'integer') {
 
         /* This is an code Example */
        $generateCode = DiscountCode::create([
             'value'  => $_GET['value'],
             'type'   => $_GET['type'], // "fixed value"=0 | "percentage"=1 | "free shipping"=2
             ‘expiration’   => $_GET[‘expiration_date’]
        ]);
 
        /* Check if code was added to your database */
        if ($generateCode) {
             $discountCode = array( "code" => $generateCode[‘code’]); //sample discount code: “ABCD124”
        }
    
 
     echo json_encode($discountCode);
 } else {
     echo json_encode(['status' => 'Incorrect REST API Key']);
 }

 ?>

https://www.yourwebsite.com/themarketer/code-generator?key=REST_KEY_FROM_THEMARKETER&value=10&type=1&expiration_date=”2022-05-27 09:00”

10. Syncing subscribers

By default, double opt-in is enabled for all our customers’ accounts. This means that whenever a user fills in a subscription form / registration form, and you ask customers for explicit permission to subscribe them to promotional emails, this needs to be taken into account.

When a user checks that they want to receive promotional emails, you will need to make a call to our Add subscriber API, which will then send the double opt-in email for confirming the newsletter subscription.

If a user doesn’t check this option, they will still be captured in theMarketer platform via the __sm_set_email event, but they will not be subscribed to the newsletter.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/add_subscriber";
    $apiKey = "MyAPI_REST_Key";
    $customerId = ‘1232394eer3414’;
 
    $client = new GuzzleHttp\Client();

 
$registerData = [
        "k" => $apiKey,
        "u" => $customerId,
        "email" => "email@example.com", //required
        "phone" => "0712345678", //optional
        "name" => "John Dave", //optional
        "gender" => "M", //optional please send the following values: M for Male / F for Female / U for Unknown,
        "country" => "RO", //optional
        "city" => "Bucharest", //optional
        "tag" => "Your tag", //optional,
        "add_tags" => "Tag1,Tag2", //optional, will add to existing tags,
        "remove_tags" => "Tag3", //optional, will remove the specified tag from the contact,
        "channels" => "email,sms", //optional, will subscribe the contact only to the specified channels,
        "attributes[attribute_name]" => "attribute_value" //optional, used for sending custom contact attributes
    ];
 
    $registerRequest = $client->request("POST", $apiURL, ["query" => $registerData, "timeout" => 2]);

11. Removing subscribers

When a subscriber unsubscribes directly from your e-commerce platform, for example via their customer profile, you will need to make an API call to our Remove Subscriber API, in order to ensure that the respective email address is also unsubscribed from theMarketer platform.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/remove_subscriber";
    $apiKey = "MyAPI_REST_Key";
    $customerId = “Customer_Id_from_theMarketer”;
 
    $client = new GuzzleHttp\Client();

 
    $registerData = [
        "k" => $apiKey,
        "u" => $customerId,
        "email" => "email@example.com", //required
    ];
 
    $registerRequest = $client->request("POST", $apiURL, ["query" => $registerData, "timeout" => 2]);

12. Syncing product reviews

If you are using our Feedback module, you can gather all the product reviews left by your customers and use them on your website.

For this, you will need to make an API call to our Product Reviews API.

The “t” parameter is expressed as a Unix timestamp and allows you to request reviews starting with a certain date. If the parameter is not provided, you will get all product reviews in the feed.

Sample code:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/product_reviews";
    $apiKey = "REST_KEY";
    $customerId = "CUSTOMER_ID";
 
    $client = new GuzzleHttp\Client();
 
    $feedbackData = [
        "k" => $apiKey,
        "u" => $customerId,
        "t" => 1656160574
    ];
 
    $statusRequest = $client->request("GET", $apiURL, ["query" => $feedbackData, "timeout" => 2]);

The API will return an XML feed with the following format:

<?xml version="1.0" encoding="UTF-8"?>
<reviews>
  <review>
      <review_id>123</review_id>
      <review_date>2022-03-01 17:44:32</review_date>
      <review_author>John Doe</review_author>
      <product_id>1234</product_id>
      <product_sku>ABC123</product_sku>
      <rating>10</rating>
      <review_text><![CDATA[This is a great product, really good quality for the price!]]></review_text>
      <media_files>
      	<media type="image">https://cdn.themarketer.com/reviews/ABCFHE12/image1.jpg</media>
      	<media type="video">https://cdn.themarketer.com/reviews/ABCFHE12/video.mp4</media>
      </media_files>
  </review>
</reviews>

13. API for Custom events

If you want to send a Custom event via API, you can use the sample code below.

Both the Event and the Email parameters are mandatory.

Keep in mind that the Custom Event needs to be defined first in theMarketer platform, under Settings -> Technical Integration.

Sample code:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/custom_events";
    $apiKey = "REST_KEY";
    $customerId = "CUSTOMER_ID";
 
    $client = new GuzzleHttp\Client();
 
    $feedbackData = [
        "k" => $apiKey,
        "u" => $customerId,
        "event" => "__sm__event_identifier",
        "email" => "customer@email.com",
        "payload" => "any type of custom information"
    ];
 
    $statusRequest = $client->request("POST", $apiURL, ["query" => $feedbackData, "timeout" => 2]);

14. Retrieve unsubscribed contacts

If you use multiple subscriber management systems, then you can use this API in order to retrive contacts who have unsubscribed from theMarketer.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/unsubscribed_emails";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_Id_from_theMarketer";
 
    $client = new GuzzleHttp\Client();

 
    $registerData = [
        "k" => $apiKey,
        "u" => $customerId,
        "date_from" => UNIX timestamp, //optional
        "date_to" => UNIX timestamp //optional
    ];
 
    $registerRequest = $client->request("GET", $apiURL, ["query" => $registerData, "timeout" => 2]);

15. Add Review API

If you want to import order or product reviews from your existing platform, you can do so by using the Add Review API. Keep in mind that orders and products sent in the API call need to already exist in theMarketer, so please be sure to import your orders first.

API call example:

<?php

$apiURL = "https://t.themarketer.com/api/v1/add_review";
$apiKey = "MyAPI_REST_Key";
$customerId = "CUSTOMER_ID";

$client = new Client();

$reviewData = [
	"k" => $apiKey,
    "u" => $customerId,
    "order_id": "7189",
    "review_date": "2022-03-01 17:44:33",
    "order_rating": 10, //ratings in theMarketer are ranged from 0 to 10
    "order_review": "here you can insert the review for the entire order",
    "product_rating": [
        "1555": 9, //ratings in theMarketer are ranged from 0 to 10, the key is product ID
        "1558": 10 //ratings in theMarketer are ranged from 0 to 10, the key is product ID
    ],
    "product_review": [
        "1555": "here you can insert the review for the product", // the key is product ID
        "1558": "here you can insert the review for the product" // the key is product ID
    ],
    "media_files": [
        "1555": "https://yourwebsite.com/image1.jpg|https://yourwebsite.com/image2.jpg",
        "1558": "https://yourwebsite.com/image1.jpg|https://yourwebsite.com/image2.jpg"
    ]
];

$registerRequest = $client->request("POST", $apiURL, ["query" => json_encode($reviewData)]);

?>

16. Send Transactional Emails

If you want to send your transactional emails through theMarketer (for example order confirmations, invoice emails etc.), you can do so by using our Transactional Emails API. Keep in mind that this service is billed separately from your theMarketer subscription.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/transactional/send-email";
    $apiKey = "MyAPI_REST_Key";
    $customerId = “Customer_Id_from_theMarketer”;
 
    $client = new GuzzleHttp\Client();

 
    $authData = [
        "k" => $apiKey,
        "u" => $customerId,
    ];

    $emailData = [
        "from" => "Yourdomain.com <sender@yourdomain.com>" //You can set a custom email address. Keep in mind that in order for this to work, you need to validate your domain in Settings -> Email settings
        "reply_to" => "reply@yourdomain.com" // You can set a custom reply-to email address
        "to" => "recipient@domain.com", //Recipient email
        "subject" => "Subject line for the email"
        "body" => "Email content goes here", //Can include HTML
        "attachments" => [
            "filename.extension" => "base64 encoded file content"
         ]
    ];
 
    $sendRequest = $client->request("POST", $apiURL, ["query" => $authData, "timeout" => 2], ["body" => json_encode($emailData)]);

?>

SMTP call example with PHPMailer:

<?php

   require 'vendor/autoload.php';
   use PHPMailer\PHPMailer\PHPMailer;

   $smtpEndpoint = "smtp1.themarketer.com";
   $apiKey = "MyAPI_REST_Key";
   $customerId = “Customer_Id_from_theMarketer”;
   $smtpPort = "2525"; //or 42525, depending on your server configuration

   $mail = new PHPMailer;
   $mail->isSMTP();

   $mail->Host = $smtpEndpoint;
   $mail->Port = $smtpPort;
   $mail->SMTPAuth = true;
   $mail->Username = $apiKey;
   $mail->Password = $customerId;
   $mail->addAddress('recipient@domain.tld', 'Receiver Name');
   $mail->Subject = 'Your email subject line';
   $mail->msgHTML(file_get_contents('message.html'), __DIR__);
   $mail->Body = 'This is just a plain text message body';
   $mail->addAttachment('attachment.extension');
   
   if (!$mail->send()) {
       echo 'Mailer Error: ' . $mail->ErrorInfo;
   } else {
       echo 'The email message was sent.';
   }

?>

17. Send Transactional SMS

If you want to send your transactional SMS through theMarketer (for example order confirmations, delivery information etc.), you can do so by using our Transactional SMS API. Keep in mind that this service is billed separately from your theMarketer subscription.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/transactional/send-sms";
    $apiKey = "MyAPI_REST_Key";
    $customerId = “Customer_Id_from_theMarketer”;
 
    $client = new GuzzleHttp\Client();

    $authData = [
        "k" => $apiKey,
        "u" => $customerId,
    ];

    $smsData = [
        "to" => "+40700000000", //Recipient phone number
        "content" => "SMS content goes here"
    ]
 
    $sendRequest = $client->request("POST", $apiURL, ["query" => $authData, "timeout" => 2], ["body" => json_encode($smsData)]);

?>

18. Loyalty API

You can retrieve all the Loyalty program information for each of your customers by using the Loyalty API. This information can be used on your website, for example you can display it in the customer’s account.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/loyalty_info";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_Id_from_theMarketer";
    $customerEmail = "examplecustomer@email.com";
 
    $client = new GuzzleHttp\Client();

 
    $data = [
        "k" => $apiKey,
        "u" => $customerId,
        "email" => $customerEmail
    ];
 
    $sendRequest = $client->request("GET", $apiURL, ["query" => $data]);

?>

Sample API response:

{
    "stats": {
        "current_tier": "Beginner", //"null" if loyalty model is set on Points
        "current_tier_points_start": 500, //"null" if loyalty model is set on Points
        "current_tier_points_end": 1999, //"null" if loyalty model is set on Points
        "next_tier": "Apprentice", //"null" if loyalty model is set on Points
        "current_points": 650,
        "redeemed_points": 2000,
        "points_about_to_expire": 0,
        "joined_on": "21.09.2023",
        "last_update": "11.12.2023",
        "membership": true
    },
    "points_history": [
        {
            "date": "2023-11-07 10:53:26",
            "points": 1000,
            "event_name": "Redeemed a reward",
            "event_type": "spend"
        },
        {
            "date": "2023-10-13 14:26:51",
            "points": 200,
            "event_name": "Placed an order",
            "event_type": "earn"
        },
    ],
    "tier_evolution": {
        "tiers": [
            {
                "name": "Rookie",
                "value": 0
            },
            {
                "name": "Beginner",
                "value": 1
            },
            {
                "name": "Apprentice",
                "value": 2
            }
        ],
        "days": [
            "21.09.2023",
            "23.09.2023",
            "27.09.2023",
        ],
        "tier": [
            0,
            1,
            2,
        ]
    },
    "points_evolution": {
        "days": [
            "21.09.2023",
            "21.09.2023",
            "21.09.2023",
        ],
        "points": [
            0,
            500,
            1000,
        ]
    },
    "rewards_history": [
        {
            "date": "2023-11-07 10:53:26",
            "points": 1000,
            "title": "10%",
            "discount_code": "MKTR-A8OKRQA8I4",
            "discount_code_expire_date": "2023-12-07",
            "used": false
        },
        {
            "date": "2023-11-07 10:44:06",
            "points": 1000,
            "title": "10%",
            "discount_code": "MKTR-RIDVIPWBPD",
            "discount_code_expire_date": null,
            "used": false
        }
    ]
}

19. Sync products API

In order to ensure faster synchronization of product information, you can sync your products in theMarketer by using our Sync products API. For the initial sync, you will need to use the “create” API method.

Sample code:

<?php
    $apiURL = "https://t.themarketer.com/api/v1/product/create";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_id_from_theMarketer";
 
    $client = new GuzzleHttp\Client();

 
    $productData = [
        "k" => $apiKey,
        "u" => $customerId,
        "id" => 123, //product id
        "sku" => "ABC123", //product sku
        "name" => "Product name",
        "description" => "Product description",
        "url" => "https://www.yourwebsite.com/sample-product-url",
        "main_image" => "https://www.yourwebsite.com/main_image.jpg",
        "category" => "Men|Clothes|Shirts", //full category tree, categories separated by |
        "brand" => "Brand name", //N/A if product does not have brand set
        "acquisition_price" => 20,
        "price" => 85,
        "sale_price" => 39, //product sale price. If product is not on sale, must be equal to price
        "sale_price_start_date" => "2022-05-02 09:00", //promo price availability start date
        "sale_price_end_date" => "2022-05-10 09:00", //promo price availability end date
        "availability" => 1, //0 - out of stock, 1 - in stock, 2 - in supplier stock
        "stock" => 200, //Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1
        "media_gallery" => [
            "https://www.yourwebsite.com/image1.jpg",
            "https://www.yourwebsite.com/image2.jpg",
            "https://www.yourwebsite.com/image3.jpg"
        ],
        "variations" => [
            [
                "id" => 1231,
                "sku" => "ABC123-S",
                "acquisition_price" => 20,
                "price" => 85, //product full price
                "sale_price" => 39, //product sale price. If product is not on sale, must be equal to price
                "size" => "S", //filled in if variation is on size, else do not send the size parameter
                "color" => "Red", //filled in if variation is on color, else do not send the color parameter
                "availability" => 1, //0 - out of stock, 1 - in stock, 2 - in supplier stock
                "stock" => 200, //Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1
            ],
            [
                "id" => 1232,
                "sku" => "ABC123-M",
                "acquisition_price" => 20,
                "price" => 85, //product full price
                "sale_price" => 39, //product sale price. If product is not on sale, must be equal to price
                "size" => "M", //filled in if variation is on size, else do not send the size parameter
                "color" => "Red", //filled in if variation is on color, else do not send the color parameter
                "availability" => 1, //0 - out of stock, 1 - in stock, 2 - in supplier stock
                "stock" => 200, //Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1
            ]
        ],
         "created_at" => "2021-04-18 08:15", //when the product was added to the store
         "extra_attributes" => [
             "first_attribute_name" => "attribute value",
             "second_attribute_name" => "attribute value",
         ]
    ];
 
    $productRequest = $client->request("POST", $apiURL, ["query" => $productData, "timeout" => 2]);
?>

Afterwards, if you want to update existing product information, such as stocks, prices, images etc., you can do so by using the “update” method.

Sample code:

<?php
    $apiURL = "https://t.themarketer.com/api/v1/product/update";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_id_from_theMarketer";
 
    $client = new GuzzleHttp\Client();

 
    $productData = [
        "k" => $apiKey,
        "u" => $customerId,
        "id" => 123, //product id
        "price" => 85, //product full price
        "sale_price" => 39, //product sale price. If product is not on sale, must be equal to price
        "sale_price_start_date" => "2022-05-02 09:00", //promo price availability start date
        "sale_price_end_date" => "2022-05-10 09:00", //promo price availability end date
        "availability" => 1, //0 - out of stock, 1 - in stock, 2 - in supplier stock
        "stock" => 200, //Total stock in pieces. If stock is 0, then availability can be 0 or 2. If stock > 0, then availability must be 1
     ];
  $productRequest = $client->request("POST", $apiURL, ["query" => $productData, "timeout" => 2]);
?>

20. Sync brands API

In order to ensure faster synchronization of brand information, you can sync your brands in theMarketer by using our Sync brands API.

Sample code:

<?php
    $apiURL = "https://t.themarketer.com/api/v1/brand/upsert";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_id_from_theMarketer";
 
    $client = new GuzzleHttp\Client();

 
    $brandData = [
        "k" => $apiKey,
        "u" => $customerId,
        "id" => 123, //product id
        "url" => "https://www.yourwebsite.com/brands/nike",
        "name" => "Brand name",
        "image_url" => "https://www.yourwebsite.com/categories/images/shirts.jpg",
     ];
 
    $brandRequest = $client->request("POST", $apiURL, ["query" => $brandData, "timeout" => 2]);
?>

21. Sync categories API

In order to ensure faster synchronization of category information, you can sync your categories in theMarketer by using our Sync categories API.

Sample code:

<?php
    $apiURL = "https://t.themarketer.com/api/v1/category/upsert";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_id_from_theMarketer";
 
    $client = new GuzzleHttp\Client();

 
    $categoryData = [
        "k" => $apiKey,
        "u" => $customerId,
        "id" => 123, //product id
        "url" => "https://www.yourwebsite.com/categories/shirts",
        "name" => "Category name",
        "image_url" => "https://www.yourwebsite.com/categories/images/shirts.jpg",
     ];
 
    $categoryRequest = $client->request("POST", $apiURL, ["query" => $categoryData, "timeout" => 2]);
?>

22. Sync events API

On-site events can now also be sent via API, in order to ensure even more accurate tracking.

Sample code:

<?php
   $DIDuuid = $_COOKIE['__sm__ss'] ?? vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4));
   setcookie('__sm__ss', $DIDuuid, strtotime('+365 days'), '/');
   $apiKey = "Tracking_Key"; // Tracking key from theMarketer account
   $restKey = "REST_API_Key"; // REST API key from theMarketer account
 
    //View homepage event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__view_homepage",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Set email event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__set_email",
          "email_address" => "john@doe.com",
          "firstname" => "John",
          "lastname" => "Doe",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Set phone event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__set_phone",
          "phone" => "0700000000",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //View category event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__view_category",
          "category" => "Men|Shoes|Sneakers",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //View brand event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__view_brand",
          "name" => "Nike",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //View product event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__view_product",
          "product_id" => "4421",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Add to cart event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__add_to_cart",
          "product_id" => "4421",
          "quantity" => "1",
          "variation" => [
              "id" => "4421",
              "sku" => "ABC123-S",
          ],
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Remove from cart event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__remove_from_cart",
          "product_id" => "4421",
          "quantity" => "1",
          "variation" => [
              "id" => "4421",
              "sku" => "ABC123-S",
          ],
         "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Add to wishlist event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__add_to_wishlist",
          "product_id" => "4421",
          "quantity" => "1",
          "variation" => [
              "id" => "4421",
              "sku" => "ABC123-S",
          ],
         "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Remove from wishlist event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__remove_from_wishlist",
          "product_id" => "4421",
          "quantity" => "1",
          "variation" => [
              "id" => "4421",
              "sku" => "ABC123-S",
          ],
         "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
    ]);
 
    //Initiate checkout event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__initiate_checkout",
          "product_id" => "4421",
          "quantity" => "1",
          "variation" => [
             "id" => "4421",
             "sku" => "ABC123-S",
          ],
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
      ],
   ]);
 
    //Initiate checkout event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__initiate_checkout",
          "product_id" => "4421",
          "quantity" => "1",
          "variation" => [
             "id" => "4421",
             "sku" => "ABC123-S",
          ],
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
      ],
   ]);
 
    //Order event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__order",
          "number" => "1234", //or text "XYZ1234"
          "email_address" => "customer@example.com",
          "phone" => "0700000000",
          "firstname" => "John",
          "lastname" => "Doe",
          "city" => "Bucharest",
          "country" => "Romania",
          "address" => "Customer billing address",
          "discount_value" => 10, // Final value of the discount, such as 10 EUR, without currency
          "discount_code" => "XYZA124", //If no discount code is used by the customer, set empty string
          "shipping" => 10,
          "tax" => 20, //final value of taxes (VAT), such as 20 EUR, without currency,
          "total_value" => 230,
          "products" => [
             [
                "product_id" => "4421",
                "price" => 100,
                "quantity" => 1,
                "variation_sku" => "ABC123-S",
             ],
             [
                "product_id" => "4425",
                "price" => 80,
                "quantity" => 1,
                "variation_sku" => "ABC125-M",
             ],
            "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
       ],
     ],
   ]);
 
    //Search event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__search",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
      ],
   ]);
 
    //Custom event
   $response = (new GuzzleHttp\Client)->post('https://t.themarketer.com/t/r', [
       'json' => [
          "did" => $DIDuuid,
          "k" => $apiKey,
          "api_key" => $restKey,
          "event" => "__sm__event_identifier",
          "url" => "'https://www.my-domain.com/accessed-url', // this could be SERVER HTTP_REFERER",
      ],
   ]);
?>

23. Reporting API

The Reporting API can give you insights into overall performance of your campaigns in theMarketer. You can get detailed statistics for Email / Push / SMS Campaigns, Automations, Audience and Signup forms.

API call example:

<?php
    require_once "vendor/autoload.php";
 
    $apiURL = "https://t.themarketer.com/api/v1/reports/get-email-campaigns";
    $apiKey = "MyAPI_REST_Key";
    $customerId = "Customer_Id_from_theMarketer";
 
    $client = new GuzzleHttp\Client();

 
    $registerData = [
        "k" => $apiKey,
        "u" => $customerId,
        "type" => "sent",
        "start" => "2024-04-01",
        "end" => "2024-04-30",
        "previous_start" => "2024-04-01", //optional
        "previous_end" => "2024-04-30", // required if previous_start is defined

     ];
 
    $registerRequest = $client->request("GET", $apiURL, ["query" => $registerData, "timeout" => 2]);
?>

The supported API endpoints are /get-email-campaigns, /get-sms-campaigns, /get-push-campaigns, /get-email-automation, /get-sms-automation, /get-push-automation, /get-audience, /get-forms-popups, /get-forms-embedded.

The available types for the /get-email-campaigns endpoint are the following: sent, open-rate, unique-open-rate, click-rate, unique-click-rate, opens, unique-opens, clicks, unique-clicks, transactions, revenue, conversion-rate, average-order-value, unsubscribed, complaints, bounced, bounce-rate, complaint-rate, unsubscribe-rate.

The available types for the /get-sms-campaigns endpoint are the following: sent, open-rate, unique-open-rate, click-rate, unique-click-rate, opens, unique-opens, clicks, unique-clicks, transactions, revenue, conversion-rate, average-order-value, unsubscribed, complaints, bounced, bounce-rate, complaint-rate, unsubscribe-rate.

The available types for the /get-push-campaigns endpoint are the following: sent, click-rate, unique-click-rate, unique-opens, clicks, unique-clicks, transactions, revenue, conversion-rate, average-order-value, unsubscribed, complaints, bounced, bounce-rate, complaint-rate, unsubscribe-rate.

The available types for the /get-email-automation endpoint are the following: sent, open-rate, click-rate, unique-click-rate, opens, unique-opens, clicks, unique-clicks, transactions, revenue, conversion-rate, average-order-value, unsubscribed, complaints, bounced, bounce-rate, complaint-rate, unsubscribe-rate.

The available types for the /get-sms-automation endpoint are the following: sent, open-rate, click-rate, unique-click-rate, opens, unique-opens, clicks, unique-clicks, transactions, revenue, conversion-rate, average-order-value, unsubscribed, complaints, bounced, bounce-rate, complaint-rate, unsubscribe-rate.

The available types for the /get-push-automation endpoint are the following: sent, click-rate, unique-click-rate, opens, clicks, unique-clicks, transactions, revenue, conversion-rate, average-order-value, unsubscribed, complaints, bounced, bounce-rate, complaint-rate, unsubscribe-rate.

The available types for the /get-audience endpoint are the following: total_subscribed_emails, total_subscribed_sms, total_subscribed_push, total_subscribed_loyalty, total_unsubscribed_emails, total_unsubscribed_sms, total_unsubscribed_push, total_unsubscribed_loyalty, total_active_emails, total_inactive_emails, total_cleaned_emails, total_bounced_emails, subscribed_emails, subscribed_sms, subscribed_push, subscribed_loyalty.

The available types for the /get-forms-popups endpoint are the following: total_impressions, total_subscribed_users, total_subscribe_rate, impressions, subscribed_users, subscribe_rate.

The available types for the /get-forms-embedded endpoint are the following: total_impressions, total_subscribed_users, total_subscribe_rate, impressions, subscribed_users, subscribe_rate.

Standard

Ecommerce

Ecommerce PRO

1. JavaScript Tracking Code
10. Syncing subscribers

Extras

13. API for Custom events
14. Retrieve unsubscribed contacts
16. Send Transactional Emails
17. Send Transactional SMS
23. Reporting API