Nativescript Google Tag Manager
Add Plugin
tns plugin add nativescript-google-tagmanager
Prequisities
Download your container from Google Tag Manager page as binary.
IOS
In your app, copy the binary file into the folder:
/App_Resources/IOS
Android
In your app, copy the binary file into the folder:
/App_Resources/Android/raw
note: if there is no raw folder inside Android folder, create it. note2: change the name of the binary file as lowercase letters, and replace - with _ (this is needed because of androids file name restrictions).
For example:
If your Binary file name is GTM-AAA11B replace its name as: gtm_aaa11b
Initalize the tracker in app.js
PLAIN JS
var application = ;var tagManager = ;applicationmainModule = "main-page";applicationcssFile = "./app.css";if applicationios//iOSvar __extends = this__extends || {for var p in b if b dp = bp;{ thisconstructor = d; }__prototype = bprototype;dprototype = ;};var appDelegate = {;{_super;}appDelegateprototype {; //Module Code to initalize};appDelegateObjCProtocols = UIApplicationDelegate;return appDelegate;}UIResponder;applicationiosdelegate = appDelegate;else//ANDROIDapplication;applicationstart;{tagManager;}
Typescript
var application = ;;applicationmainModule = "main-page";applicationcssFile = "./app.css"; if applicationios //iOS implements UIApplicationDelegate public static ObjCProtocols = UIApplicationDelegate; : boolean ; //Module Code to initalize return true; applicationiosdelegate = MyDelegate; else //ANDROID application; applicationstart; { googleTagManager;}
Methods
Log Anything
// category and action are not optional, label and value aregoogleTagManager;googleTagManager;