multi-platform-tracking-sdk
Version:
🚀 Professional Multi-Platform Tracking SDK for Facebook/Meta Pixel, Instagram Analytics & Google Tag Manager | Zero Dependencies | TypeScript Ready | Privacy Compliant GDPR/CCPA | Created by A. Z. M. Arif | Code Encover
194 lines (193 loc) • 5.96 kB
TypeScript
/**
* Instagram Tracking SDK
*
* Instagram uses the same Facebook/Meta Pixel and Conversion API infrastructure
* but with Instagram-specific parameters and tracking patterns.
*
* This tracker extends the existing Meta tracking capabilities with
* Instagram-specific features and optimizations.
*/
export interface InstagramEngagementData {
contentType?: 'photo' | 'video' | 'carousel' | 'story' | 'reel' | 'igtv';
contentId?: string;
contentName?: string;
contentCategory?: string;
creatorId?: string;
creatorName?: string;
hashtags?: string[];
location?: string;
duration?: number;
isSponsored?: boolean;
campaignId?: string;
}
export interface InstagramShoppingData {
productId: string;
productName?: string;
price: number;
currency?: string;
category?: string;
brand?: string;
availability?: 'in_stock' | 'out_of_stock' | 'preorder';
imageUrl?: string;
productUrl?: string;
merchantId?: string;
catalogId?: string;
isFromShop?: boolean;
shoppingSource?: 'feed' | 'story' | 'explore' | 'search' | 'profile';
}
export interface InstagramUserData {
userId?: string;
username?: string;
isFollower?: boolean;
followersCount?: number;
accountType?: 'personal' | 'business' | 'creator';
verificationStatus?: 'verified' | 'unverified';
interests?: string[];
demographics?: {
age?: number;
gender?: 'male' | 'female' | 'other';
location?: string;
language?: string;
};
}
export interface InstagramConfig {
pixelId: string;
accessToken?: string;
debug?: boolean;
instagramAppId?: string;
enableInstagramAPI?: boolean;
defaultCurrency?: string;
testEventCode?: string;
}
export declare class InstagramTracker {
private pixelTracker;
private conversionTracker?;
private config;
constructor(config: InstagramConfig);
/**
* Initialize Instagram tracking
*/
init(): void;
/**
* Set Instagram-specific context for tracking
*/
private setInstagramContext;
/**
* Track Instagram content engagement
*/
trackContentEngagement(action: 'like' | 'comment' | 'share' | 'save' | 'view' | 'click', data?: InstagramEngagementData): void;
/**
* Track Instagram Story interaction
*/
trackStoryInteraction(action: 'view' | 'tap_next' | 'tap_back' | 'tap_exit' | 'swipe_up' | 'reply', data?: InstagramEngagementData): void;
/**
* Track Instagram Reels interaction
*/
trackReelsInteraction(action: 'view' | 'like' | 'comment' | 'share' | 'save' | 'follow', data?: InstagramEngagementData): void;
/**
* Track Instagram Shopping events
*/
trackShoppingEvent(action: 'product_view' | 'add_to_cart' | 'add_to_wishlist' | 'purchase' | 'shop_visit', data: InstagramShoppingData): void;
/**
* Track Instagram user follow/unfollow
*/
trackFollowAction(action: 'follow' | 'unfollow', targetUser: {
userId?: string;
username?: string;
accountType?: 'personal' | 'business' | 'creator';
}): void;
/**
* Track Instagram search
*/
trackSearch(searchTerm: string, searchType?: 'hashtag' | 'user' | 'place' | 'general'): void;
/**
* Track Instagram Live interaction
*/
trackLiveInteraction(action: 'start_watching' | 'stop_watching' | 'comment' | 'like' | 'share', data?: {
liveId?: string;
creatorId?: string;
viewerCount?: number;
duration?: number;
}): void;
/**
* Track Instagram ad interaction
*/
trackAdInteraction(action: 'view' | 'click' | 'like' | 'comment' | 'share' | 'save' | 'hide', adData?: {
adId?: string;
campaignId?: string;
adSetId?: string;
adType?: 'photo' | 'video' | 'carousel' | 'story' | 'reel';
placementType?: 'feed' | 'story' | 'explore' | 'reel';
}): void;
/**
* Set Instagram user context
*/
setUserContext(userData: InstagramUserData): void;
/**
* Track Instagram profile visit
*/
trackProfileVisit(profileData: {
userId?: string;
username?: string;
accountType?: 'personal' | 'business' | 'creator';
isOwn?: boolean;
}): void;
/**
* Track Instagram hashtag interaction
*/
trackHashtagInteraction(action: 'view' | 'follow' | 'unfollow', hashtag: string): void;
/**
* Track Instagram direct message interaction
*/
trackDirectMessage(action: 'send' | 'receive' | 'read' | 'react', messageData?: {
conversationId?: string;
messageType?: 'text' | 'photo' | 'video' | 'voice' | 'story_reply';
isGroupMessage?: boolean;
}): void;
/**
* Get configuration
*/
getConfig(): InstagramConfig;
/**
* Update configuration
*/
updateConfig(newConfig: Partial<InstagramConfig>): void;
/**
* Check if tracker is ready
*/
isReady(): boolean;
/**
* Get Instagram-specific recommendations based on account type
*/
getRecommendedEvents(accountType?: 'personal' | 'business' | 'creator'): string[];
/**
* Debug Instagram tracking data
*/
debugInstagramData(): void;
}
export declare const InstagramHelpers: {
/**
* Extract hashtags from text
*/
extractHashtags(text: string): string[];
/**
* Extract mentions from text
*/
extractMentions(text: string): string[];
/**
* Format Instagram currency for different regions
*/
formatCurrency(amount: number, currency?: string): string;
/**
* Generate Instagram event ID
*/
generateEventId(prefix?: string): string;
/**
* Validate Instagram username
*/
isValidUsername(username: string): boolean;
/**
* Get Instagram content type from URL
*/
getContentTypeFromUrl(url: string): InstagramEngagementData["contentType"];
};