-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleTagManager.alusus
More file actions
47 lines (43 loc) · 1.98 KB
/
GoogleTagManager.alusus
File metadata and controls
47 lines (43 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright (C) 2026 Sarmad Abdullah
*
* This file is part of Alusus GoogleTagManager library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
module GoogleTagManager {
@assetsRoute["/gtagmanager/"] def assetsRoute: ("$Assets/", "GtagManagerAssets/");
function initializeFrontend(id: CharsPtr): Srl.SrdRef[Promises.Promise[Int]] {
return loadJsScript(String.format("https://www.googletagmanager.com/gtag/js?id=%s", id))
.then[Int](closure (Int, p: ref[Promises.Promise[Int]]) {
p.resolve(loadJsScript("/gtagmanager/binding.js"));
}).then[Int](closure (Int, p: ref[Promises.Promise[Int]]) {
callCustomJsFn("configureGoogleTagManager", id);
p.resolve(0);
});
}
function pushEvent(eventName: CharsPtr, jsonArg: CharsPtr) {
def args: String = String.format("[\"event\", \"%s\", %s]", eventName, jsonArg);
callCustomJsFn("pushGoogleTagEvent", args);
}
function pushConversionEvent(id: String, conversionId: String, transactionId: String) {
def args: String = String.format(
"[\"event\", \"conversion\", {\"send_to\": \"%s/%s\", \"transaction_id\": \"%s\"}]",
Json.escape(id).buf,
Json.escape(conversionId).buf,
Json.escape(transactionId).buf
);
callCustomJsFn("pushGoogleTagEvent", args);
}
}