If you are looking for a flexible way to track your affiliate marketing campaigns without constantly editing your website's code, Affise Web SDK integration with Google Tag Manager (GTM) is the perfect solution. GTM allows you to deploy and manage your tracking scripts with ease, giving you the power to track clicks and conversions accurately and efficiently.
In this step-by-step guide, you can view how to configure end-to-end Affise tracking in GTM.
🔎 Before you begin, make sure you have the following:
An active Affise account with white label domain (recommended).
A Google Tag Manager container installed on your website with a trigger configured for your desired conversion events.
Set up Affise click tracking for landing pages
On this step, you should capture the initial touchpoint when a user comes from an affiliate link. This tag should only fire once on the user's landing page to ensure data accuracy.
Create a new custom HTML tag. For that, in your GTM account, go to Tags > New. Name your tag (e.g., "Affise - Click Tracking"). For the tag type, select Custom HTML.
Add the following script to the HTML field.
<script src="https://csdemo.g2afse.com/websdk.js"></script>
<script>
var offerId = ASDK.urlParameter('offer_id') || 'DEFAULT_OFFER';
var affiliateId = ASDK.urlParameter('aff_id') || 'DEFAULT_AFFILIATE';
ASDK.click({
offer_id: offerId,
affiliate_id: affiliateId,
user_agent: navigator.userAgent
})
.then(function(clickId) {
console.log('Tracking initialized:', clickId);
})
.catch(function(error) {
console.error('Tracking error:', error.message);
});
</script>This code captures the offer_id and aff_id from the URL and generates a click.
Add the All Pages - Page View trigger. It generates the click when the user visits the page. If the click is already generated, then it won’t be created on the subsequent visits of the page.
Set up Affise conversion tracking in GTM
Next, you should track when a user completes a key action, like a purchase or a form submission. This conversion tag links the action back to the original click.
Create a new conversion tag. For that, go to Tags > New, name it "Affise - Conversion Tracking" and select the Custom HTML tag type.
2. Add the conversion tracking script below.
<script src="https://csdemo.g2afse.com/websdk.js"></script>
<script>
var offerId = ASDK.urlParameter('offer_id');
var clickId = ASDK.clickId(offerId);
ASDK.conversion({
click_id: clickId,
offer_id: offerId,
status: '1' // 1 = confirmed
})
.then(function() {
console.log('Conversion tracked successfully');
})
.catch(function(error) {
console.error('Error tracking conversion:', error);
});
</script>
This script is smart, it retrieves the offer_id saved in the previous step and uses it to find the correct clickid automatically stored by the SDK.
3. Click Triggering and select the event that defines a conversion. This will be unique to your website. Common examples include:
A Page View trigger for a "Thank You" or "Order Confirmation" page (e.g.,
Page URL contains /thank-you).A Custom Event trigger that fires when a specific action, like a purchase, is pushed to the data layer.
Ensure accurate tracking in Safari and other browsers
To ensure your tracking works reliably across all browsers, especially those with privacy features like Safari's Intelligent Tracking Prevention (ITP), your tracking links must contain the necessary parameters. The click tracking script relies on this data being present in the URL when the user first lands on your site.
Make sure your tracking links are formatted correctly: https://yourwebsite.com/?offer_id={offer_id}&aff_id={pid}
Please contact the Affise Customer Support team regarding all raised questions via the e-mail: [email protected].
